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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
yswddd
Posts: 37
Registered: ‎02-09-2009
Accepted Solution

How to use a good ObjectChoiceField

I have to use ObjectChoiceField,but the default ObjectChoiceField is not good looking,who can help me for some code ,thanks
Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008

Re: How to use a good ObjectChoiceField

Describe, How do you want to see your ObjectChoiceField.

Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
Developer
yswddd
Posts: 37
Registered: ‎02-09-2009

Re: How to use a good ObjectChoiceField

When I focus the focus on,it didn't have any change . I think it should be highlight or else,tell me how to do this issue,thanks
Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008

Re: How to use a good ObjectChoiceField

When you have a ObjectChoiceField, you can set the index to display the selected item. Looks depends on the Theme of BB device. For ObjectChoiceField Label you can paint the background or change the color of the text.

Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
Developer
yswddd
Posts: 37
Registered: ‎02-09-2009

Re: How to use a good ObjectChoiceField

Here is my code:

class MyChoiceField extends ObjectChoiceField{
 
 MyChoiceField (String label, Object[] choices,long style,int choice){
  super(label,  choices,choice,style);
  //this.setExtent(getContentWidth()+50, getHeight());
 }
 
 public void layout(int width, int height){
        super.layout(width, height);
        setExtent(getWidth() + 10, getPreferredHeight());       
        //setVirtualExtent(width, managerHeight);              
    }
 

    

    
 public void paint(Graphics graphics){
  graphics.setColor(Color.WHITE);
  graphics.fillRect(0, 0, getWidth(), getHeight());
  graphics.setColor(Color.BLACK);
        int w = 10;
        int h = w>>1;       
        for (int i=0; i<=h; i++) {
         graphics.invert(i, i,  w - (i << 1), 1);
            //System.out.println(i + "~~~~  " + i + " " + i + " " + (w - (i << 1)) + " 1");
        }       
        graphics.drawRect(1, 0, getWidth()-1, getHeight());


        super.paint(graphics);

    }

public void drawFocus(Graphics graphics,boolean on){
       super.drawFocus(graphics, on);     
 }

 

but when the item is focused on ,  there is no change happen,not like the text or eles,help me.

Please use plain text.
Developer
yswddd
Posts: 37
Registered: ‎02-09-2009

Re: How to use a good ObjectChoiceField

And another question: how to change color of the background or text., override the paint method just as my code or else? thanks.
Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008

Re: How to use a good ObjectChoiceField

Hi I modified ur code this way to check the focusChange and changing text.

class MyChoiceField extends ObjectChoiceField { boolean onFocuss; MyChoiceField (String label, Object[] choices,int choice,long style) { super(label, choices,choice,style); } public void paintBackground(Graphics graphics) { if(onFocuss) { graphics.clear(); int color = graphics.getColor(); graphics.setColor( 0x00FF00 ); } else { graphics.clear(); int color = graphics.getColor(); graphics.setColor( 0x000000 ); } } public void onFocus(int dir) { onFocuss = true; invalidate(); } public void onUnfocus() { onFocuss = false; invalidate(); } }

 


Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.