Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
wpbbmg
Posts: 83
Registered: ‎02-19-2010
My Device: Not Specified
Accepted Solution

LabelField: transparent background

Hello,

 

how can set the background transperant by onFocus and onUnfocus? (4.5)

 

Regards

Maja

Developer
hagen
Posts: 100
Registered: ‎04-07-2009
My Device: Not Specified

Re: LabelField: transparent background

Have considered about using setVisualState(int) ?

Developer
wpbbmg
Posts: 83
Registered: ‎02-19-2010
My Device: Not Specified

Re: LabelField: transparent background

I'm using JDE 4.5 there is no setVisualState() :smileysad:

 

And when I understand the documentation I can set the visuality of the Field, not of the background!

 

My Problem is, that every focusable LabelField is marked with a darker Background, but I have an image as background and then I see the background of the label and not the image. Because of that, I want a transparent background of a focusable field.

Developer
hagen
Posts: 100
Registered: ‎04-07-2009
My Device: Not Specified

Re: LabelField: transparent background

Could you show the code?

Developer
wpbbmg
Posts: 83
Registered: ‎02-19-2010
My Device: Not Specified

Re: LabelField: transparent background

I don't know what I can show you!

 

 

HorizontalFieldManager obsDataManagerTop = new HorizontalFieldManager(USE_ALL_WIDTH | FIELD_VCENTER | FOCUSABLE);
		
CustomLabelField tObs = new CustomLabelField("1", FOCUSABLE | USE_ALL_WIDTH | DrawStyle.HCENTER, 15, Font.BOLD);
							obsDataManagerTop.add(tObs);

 

 

This is what I can show you! I have an HFM and in this HFM I have a Custom LabelField. Know the Problem is, when the LabelField is focusable it has an darker Background onFocus. I don't set this! This is so! :smileywink:

 

But I want to tell the LabelField when it is onFocus that the Background is transparent!

 

Is there a chance with 4.5?

Developer
yosoh
Posts: 213
Registered: ‎07-18-2008
My Device: Not Specified

Re: LabelField: transparent background

did you take  a look at this sample?

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800608/...

--------------------------------------------------
problemSolved() ? kudosPlease():kudosPlease();
Developer
hagen
Posts: 100
Registered: ‎04-07-2009
My Device: Not Specified

Re: LabelField: transparent background

Hey, sorry to bother you, I'm just a little less busy today. What I wanted to see, were the relevant methods of your custom labelfield, e.g. where you set/paint the image as background, onFocus(), drawFocus() like that, but most likely I won't be able to help. So, sorry again and good luck. Hagen

Developer
wpbbmg
Posts: 83
Registered: ‎02-19-2010
My Device: Not Specified

Re: LabelField: transparent background

that's the problem I have! :smileywink: I don't know what I can write in the paint method that

 

And know I have a paint method and I don't know what I can write that the background is transparent

 

My Custom LabelField:

 

 

import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.component.LabelField;

public class CustomLabelField extends LabelField {
	
	public CustomLabelField(String label, long style, int size, int type){
		super(label, style);
		super.setFont(FieldFont(size, type));
	}
	
	private static Font FieldFont(int size, int type) {
        try {
            FontFamily fontFamily = FontFamily.forName("BBClarity");
            return fontFamily.getFont(Font.BOLD, size, Ui.UNITS_pt);
        } catch (ClassNotFoundException ex) {

        }
        return null;
    }
	
	protected void paint(Graphics graphics)
    {
    	if(this.isFocus())                
		{
		    // make background transparent
		}
    	else
    	{
    		// make background transparent
    	}
        
	    graphics.clear();
	    super.paint(graphics);  
	    invalidate();   
    }
}

 

Does it help you to help me? :smileywink:

 

Developer
wpbbmg
Posts: 83
Registered: ‎02-19-2010
My Device: Not Specified

Re: LabelField: transparent background

Ok know I try some options an know I have the Problem, that I want to change the text color and don't the background! But when I say setColor(Color.WHITE) without invoke setBackgroundColor() all is white, background and text!

 

How can I set the text color without to set the background, because set the background transparent is apparently only possible from Version 4.6 and I have to use 4.5! :-(

 

My paint method for the label:

 

 

protected void paint(Graphics graphics)
    {
    	if(this.isFocus())                
	{

           graphics.setColor(0xFFDF00);
	}
    	else
    	{
    	   graphics.setColor(Color.WHITE);
    	}
        
	graphics.clear();
	super.paint(graphics);  
	invalidate();   
    }

 

 

Developer
wpbbmg
Posts: 83
Registered: ‎02-19-2010
My Device: Not Specified

Re: LabelField: transparent background

Ok I found out how to set the text color without setting the background (delete the graphics.clear() method :smileywink: ) an know the text changes it's color when focus is on it, but the only problem I have is, that the field which is focusable changes it background to an darker blue. can anyone help me to find out how to stop it? changing text color is enough for me, I don't want to have a darker background!

 

Here's the manager with background image:

 

 

VerticalFieldManager fieldManagerAll = new VerticalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH | NO_VERTICAL_SCROLL){
protected void paintBackground( Graphics g ) {
g.setColor(Color.WHITE);
super.paintBackground( g );
g.drawBitmap( 0, 0, daily.getWidth( ), daily.getHeight( ), daily, 0, 0 );
}
};

 

And here's the paint method from the manager which changes the text color on focus:

 

 

protected void paint(Graphics graphics)
{
  if(this.isFocus())                
  {
	graphics.setColor(0xFFDF00);
  }
  else
  {
	graphics.setColor(Color.WHITE);
  }
        
  super.paint(graphics);  
  invalidate();   
}

 

Know anyone an idea?