BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 12-06-2007, 07:26 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default EditField and Backgroundcolor

Please Login to Remove!

Hi,
i've got an EditField in a HorizontalFieldManager. Now I want to change the Backgrundcolor of the EditField. I searched for it in the forum and found this Change EditField background color?

But the compiler sais that it's not a valid function for the EditField.

So how can I change the BG-Color?

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-06-2007, 07:43 AM   #2 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think the best way is to create a ColouredEditField that extends EditField.
Create additional constructors, with String text, int color; for example, and overwrite paint:

Code:
public void paint(Graphics graphics) {
    graphics.setBackgroundColor(color);
    graphics.clear();  
    super.paint(graphics);
}
You can also overwrite onFocus() to let it change its color while selected.

hth,
simon
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 12-06-2007, 09:11 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for the reply, i've tried this here:
Code:
//....
field = new myEdit("1","2");
//...
public class myEdit extends EditField {
         public boolean farbe;
    public myEdit(String label, String defaultString) {
        super(label, defaultString);
    }

    protected void layout(int width, int height) {
        setExtent(100, getFont().getHeight());
    }

    public void paint(Graphics graphics) {
            graphics.clear();
            graphics.setBackgroundColor(Color.CORNFLOWERBLUE);
            super.paint(graphics);
     }
    
    public void setFarbe(boolean ok) {
        farbe = ok;
    }


    public boolean isFocusable() {
        return true;
    }
} // end of myEdit
but there is still the white background...

hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-06-2007, 09:15 AM   #4 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

add
Code:
super.paint(graphics);
to the paint method
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 12-06-2007, 09:34 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

ah ok, now i've found the little problem.
the EditField is in a HorizontalFieldManager, i have to add the paint method for the manager and not for the editField...

ok now it works, but there is still one problem left:
when i type a text the backgroundcolor switches back to white, so i have to paint the background again, but how?

thanks so far

hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 09-10-2008, 02:51 PM   #6 (permalink)
New Member
 
Join Date: Sep 2008
Model: 8800
PIN: N/A
Carrier: airtel
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

public void onFocus(int direction)
{
_oldBackgroundColor = _backgroundColor; //backup
_backgroundColor = Color.BLUE;
invalidate();
}

public void onUnfocus()
{
_backgroundColor = _oldBackgroundColor;
invalidate();
}
Offline  




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