BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 02-08-2006, 06:59 PM   #1
shan
Knows Where the Search Button Is
 
Join Date: Nov 2005
Model: 7290
Posts: 16
Default Font Color

Please Login to Remove!

I would like to add some color to text my application.

I found the package
net.rim.device.api.ui.Color;


how to use the color in program

Please give some suggestions.
Offline  
Old 02-08-2006, 10:29 PM   #2
Mark Rejhon
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Default

Use the net.rim.device.api.ui.Graphics object, using RGB 0x00RRGGBB value.
Graphics.setColor(RGB);
To get the graphics object, use MainScreen.getGraphics()

Code:
// Do this inside a method in your class that implements MainScreen
Graphics g = this.getGraphics();
g.setColor(( red << 16 ) + ( green << 8 ) + blue); 
// Now you can draw your text. It will be the new color.
Or you can use values from the Color class, to set commonly used colors.
Code:
Graphics g = this.getGraphics();
g.setColor(Color.BLUE);
__________________
Thanks,
Mark Rejhon
Author of XMPP extension XEP-0301:
www.xmpp.org/extensions/xep-0301.html - specification
www.realjabber.org - open source

Last edited by Mark Rejhon; 02-08-2006 at 10:32 PM..
Offline  
Old 02-07-2007, 09:18 AM   #3
bdowling
Thumbs Must Hurt
 
Join Date: Jan 2007
Model: 8800
Carrier: Orange
Posts: 181
Default No Luck :(

Thought this was exactly what I was looking for, but when trying:

Code:
inal Graphics g = this.getGraphics();
final int currentColor = g.getColor();

g.setColor( 255 << 16 ); // also tried g.setColor( Color.RED );

add( new RichTextField( "Error", RichTextField.NON_FOCUSABLE ) );
 
g.setColor( currentColor );
The RichTextField is still black :(
Is there anyway to set the color of the rich text field directly?

TIA, Ben
Offline  
Old 02-07-2007, 11:35 PM   #4
adwiv
Thumbs Must Hurt
 
Join Date: Oct 2006
Model: 8707g
Carrier: Hutch
Posts: 73
Default

Override the paint method, and use call super.paint after setting the color. No other way I know of.
Offline  
Old 02-08-2007, 04:11 AM   #5
bdowling
Thumbs Must Hurt
 
Join Date: Jan 2007
Model: 8800
Carrier: Orange
Posts: 181
Default

OK got it working. Thanks
Offline  
Old 08-20-2007, 10:03 AM   #6
genvej
Thumbs Must Hurt
 
Join Date: Jul 2007
Model: 8800
PIN: N/A
Carrier: TDC
Posts: 115
Default

can you plz provide a complete example as im in the dark about calling the super.paint
Offline  
Old 08-20-2007, 10:42 PM   #7
arifzaman
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
Default

Hi genvej,

Try with the following code:

Code:
RichTextField colorField = new RichTextField("Hello") {
  // Override the paint method to set Color.
  public void paint(Graphics graphics) {
    graphics.setColor(Color.RED);
    super.paint(graphics);
  }
};
add(colorField);
Hope this will help!

Cheers,
ARIF
Offline  
Old 08-22-2007, 06:34 AM   #8
genvej
Thumbs Must Hurt
 
Join Date: Jul 2007
Model: 8800
PIN: N/A
Carrier: TDC
Posts: 115
Default

Quote:
Originally Posted by arifzaman View Post
Hi genvej,

Try with the following code:

Code:
RichTextField colorField = new RichTextField("Hello") {
  // Override the paint method to set Color.
  public void paint(Graphics graphics) {
    graphics.setColor(Color.RED);
    super.paint(graphics);
  }
};
add(colorField);
Hope this will help!

Cheers,
ARIF

thx a bunch... however... Im also interested in changing the font, which your example doesnt let me do... i tried

public void paint(Graphics graphics) {
graphics.setFont(FieldFont());
graphics.setColor(Color.RED);
super.paint(graphics);
}

public static Font FieldFont(){
try {
FontFamily theFam = FontFamily.forName("BBCASUAL");
return theFam.getFont(net.rim.device.api.ui.Font.PLAIN, 31);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return null;
}
Offline  
Old 08-22-2007, 09:37 AM   #9
jfisher
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Default

you tried:

colorField.setFont(FieldFont());


?
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 08-25-2007, 11:04 PM   #10
arifzaman
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
Default

Welcome genvej!

Quote:
Originally Posted by genvej View Post
public void paint(Graphics graphics) {
graphics.setFont(FieldFont());
graphics.setColor(Color.RED);
super.paint(graphics);
}
Try with the following code:

Code:
RichTextField colorField = new RichTextField("Hello") {
	// Override the paint method to set Font and Color.
	public void paint(Graphics graphics) {
	  setFont(FieldFont());
	  graphics.setColor(Color.RED);
	  super.paint(graphics);
	}
};
add(colorField);
Cheers,
ARIF
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


2X Honeywell Xenon 1902GSR-2 Handheld Barcode Scanner 1902GSR-2-23105 w Base USB picture

2X Honeywell Xenon 1902GSR-2 Handheld Barcode Scanner 1902GSR-2-23105 w Base USB

$54.99



4X Honeywell Xenon 1902GSR-2 Handheld Barcode Scanner 1952GSR-2-31886 w Base USB picture

4X Honeywell Xenon 1902GSR-2 Handheld Barcode Scanner 1952GSR-2-31886 w Base USB

$175.99



INTEL XEON E5 2520V2 E5 2620V2 SR1AN 2.10 GHZ Core Processor 3401A832 picture

INTEL XEON E5 2520V2 E5 2620V2 SR1AN 2.10 GHZ Core Processor 3401A832

$12.00



4x NCR Xenon 1902 Handheld Barcode Scanner 1902GSR-2 w/ Battery 497-0434401 picture

4x NCR Xenon 1902 Handheld Barcode Scanner 1902GSR-2 w/ Battery 497-0434401

$99.50



1 Pc Home Intel Xeon Silver Sclip 4110 Linux   - NEW picture

1 Pc Home Intel Xeon Silver Sclip 4110 Linux - NEW

$245.00



Kit xeon Maxgeek DSE6020 MKII Generator Controller Generator Set Control Panel picture

Kit xeon Maxgeek DSE6020 MKII Generator Controller Generator Set Control Panel

$125.00







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.