BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 12-10-2007, 04:05 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 - repaint on enter/leave

Please Login to Remove!

hi,
i want to change the backgroundcolor of my EditField.
once the user sets the cursor into the field it schould switch to blue an after typing in some text an leaving it an other procedure should check the input and set the backgroundcolor to green or red.

but i don't have an idea how i should get it to work

doeas anybody have an good idea to this?

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-10-2007, 10:32 AM   #2 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I use
protected void onUnfocus() {
}
and
protected void onFocus() {
}
to handle custom field management on focus changes
Offline  
Old 12-11-2007, 03:06 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

ok, thanks that works =)

now i have to know how to repaint the editField because the cursor leaves a blank space

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-11-2007, 09:46 AM   #4 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I use
onUnfocus() {
this.invalidate();
}

this seems to repatint the field properly for me
Offline  
Old 12-12-2007, 02:05 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

hmmm insteat of the white blank space now there is a blue space from the cursor

have i to change the cusor-color, if it is possible, and if it is, how?

or is there another simple way?

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-13-2007, 12:54 PM   #6 (permalink)
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Post Thanks: 1
Thanked 0 Times in 0 Posts
Default

The problem is simply you're repainting the textbox before the cursor is properly repainted.

Best:
Try an override instead of using onUnfocus. (I'd have to look up JDE for the correct override, if one exists) Then call the "super." method to let the field finish cursor paint before you call this.invalidate( ) ... I'd rather use an override of the super method that controls the cursor painting, and force the cursor painting (to make cursor dissappear first) then invalidate to do our painting.

Could work:
Another idea is to maybe try "invokeLater" the invalidate event, or a very short timer event in onUnfocus that calls the invalidate a few milliseconds later.

Also could work:
Another idea is to set a flag in onUnfocus which is detected by your paint( ) event, and do the "make the cursor dissappear" (and rest the flag) before repainting the textbox color.

Lots of easy workarounds.
__________________
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 : 12-13-2007 at 12:57 PM.
Offline  
Old 12-14-2007, 01:44 AM   #7 (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

Quote:
Originally Posted by Mark Rejhon View Post
The problem is simply you're repainting the textbox before the cursor is properly repainted.

Best:
Try an override instead of using onUnfocus. (I'd have to look up JDE for the correct override, if one exists) Then call the "super." method to let the field finish cursor paint before you call this.invalidate( ) ... I'd rather use an override of the super method that controls the cursor painting, and force the cursor painting (to make cursor dissappear first) then invalidate to do our painting.
ok, i also take a look at

Quote:
Originally Posted by Mark Rejhon View Post
Could work:
Another idea is to maybe try "invokeLater" the invalidate event, or a very short timer event in onUnfocus that calls the invalidate a few milliseconds later.
maybe i do something wrong, but doesn't work
Code:
protected void onUnfocus() {
     UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
                try {
                 this.invalidate(); /* --> cannot find symbol
symbol: method invalidate()*/
                } catch (Exception exT) {System.out.println("PaintError: "+exT);}
            }
        });// */
}
Quote:
Originally Posted by Mark Rejhon View Post
Also could work:
Another idea is to set a flag in onUnfocus which is detected by your paint( ) event, and do the "make the cursor dissappear" (and rest the flag) before repainting the textbox color.
i don't have any idea of this one...

Quote:
Originally Posted by Mark Rejhon View Post
Lots of easy workarounds.
i see

thanks so far, hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-14-2007, 02:46 AM   #8 (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

this is referring to the runnable, you have to refer to the outer class with Classname.this.invalidate()
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 12-14-2007, 11:02 AM   #9 (permalink)
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Post Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by simon.hain View Post
this is referring to the runnable, you have to refer to the outer class with Classname.this.invalidate()
This is correct. Replace Classname with the name of your main class of the file (i.e. same as your filename before the ".java" extension)

More explanation to others who find this confusing: So if you've got ClassName.java with "class ClassName" and you've got an embedded class "class EmbeddedClass" inside ClassName. Any code inside EmbeddedClass need to refer to the original class 'this' pointer by using "ClassName.this.method()" instead of just "this.method()". That way, the compiler knows to which 'this' is being referred to.

A good java tip to any java programer.
__________________
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 : 12-14-2007 at 11:26 AM.
Offline  
Old 01-07-2008, 05:52 AM   #10 (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

hwyho,
some time ago, but i just enjoy my holidays ;)

i've tried this here:
Code:
protected void onUnfocus() {
    UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
                try {
                 ActionsScreen2.this.invalidate(); /* --> cannot find symbol
symbol: method invalidate()*/
                } catch (Exception exT) {System.out.println("PaintError: "+exT);}
            }
        });// */
     
}
so i don't have a solution yet :(

any other ideas, or do i still have some mistakes?

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-17-2008, 05:51 AM   #11 (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

still got no soplution.
here is what i have tried so far:
PHP Code:
public class myManager extends HorizontalFieldManager {
  private 
int managerWidth;
  private 
int managerHeight;
  private 
EditField editField;
  private 
boolean farbe;
  private 
int eID;
  private 
Graphics g null;

public 
myManager(int widthint heightboolean _colorint _id) {
    
super(Manager.NO_VERTICAL_SCROLL);
    
managerWidth width;
    
farbe _color;
    
eID _id;
    
managerHeight height;
    
HorizontalFieldManager vfm =new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL);
    
editField = new EditField("","",3,EditField.FILTER_NUMERIC){
        protected 
void onUnfocus() {
            
invalidate();
        }
    };
    
vfm.add(editField);
    
add(vfm);
}
public 
void setFarbe(boolean ok) {
    
farbe ok;
}

protected 
void onUnfocus() {
    
invalidate();
    
UiApplication.getUiApplication().getActiveScreen().updateDisplay();    
}

protected 
void onFocus() {
    
/*invalidate();
    UiApplication.getUiApplication().getActiveScreen().updateDisplay();
  */
}


public 
void sublayout(int widthint height) {
  if (
managerWidth == 0) {
     
managerWidth width;
  }
  if (
managerHeight == 0) {
     
managerHeight height;
  }
  
super.sublayout(managerWidthmanagerHeight);
  
setExtent(managerWidth,managerHeight);
}


public 
String getText() {
    if (
editField.getText() == "") {
        return 
"0";
    } else {
        return 
editField.getText();
    }
}
 public 
void paint(Graphics graphics) {
     if (
== nullgraphics;
        
graphics.clear();
        
//super.paint(graphics);
        
if (farbe == true) {
            
graphics.setColor(0xf7ce40);
            
graphics.fillRect(0,0,Graphics.getScreenWidth(),_font.getHeight()+1);
            
graphics.setColor(Color.BLACK);
        } else {
            
graphics.setColor(Color.WHITE);
            
graphics.fillRect(0,0,Graphics.getScreenWidth(),_font.getHeight()+1);
            
graphics.setColor(Color.BLACK);
        }
        
graphics.setColor(Color.BLACK);
        
graphics.drawLine(0,managerHeight-3,50,managerHeight-3);
        
int i 0;
        while (
1000){
            
++;
        }
        
super.paint(graphics);
 }
  
public 
void setText(String text) {
    
editField.setText(text);
}
}
// end of customField

     
public class myEdit extends EditField {
    public 
boolean farbe;
    public 
myEdit(String labelString defaultString) {
        
super(labeldefaultString);
    }

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

    public 
void paint(Graphics graphics) {
         
graphics.clear();
        if (
farbe == true) {
            
graphics.setBackgroundColor(0xf7ce40);
            
graphics.drawRect(0,15,35,1);
            
super.paint(graphics);
        }
//*/
        
graphics.drawLine(0,0,10,0);
        
graphics.setColor(Color.BLACK);
        
invalidate();
        
super.paint(graphics);
        
    }
    
    public 
void setFarbe(boolean ok) {
        
farbe ok;
    }
    public 
void onUnfocus() {
       
/* 
        invalidate();
        UiApplication.getUiApplication().getActiveScreen().doPaint();
        UiApplication.getUiApplication().getActiveScreen().invalidate();
        UiApplication.getUiApplication().getActiveScreen().invalidateLayout();
        UiApplication.getUiApplication().getActiveScreen().updateDisplay();
        */
        //invalidate();

    
}
    
    protected 
void onFocus() {
        
//invalidate();
    
}
    public 
boolean isFocusable() {
        return 
true;
    }
    public 
void redraw2() {
    }
    
    protected 
void drawFocus(Graphics graphicsboolean on) {
    }
// end of myEdit 
the result of this code is:

when i leave the first editfield do go to the second one, than the cursor in field one flashes for a millisecond an then the focus-bar is in the first an second field, but the second field has the real focus.

maybe someone could say, where i habe to repaint the field in the right moment ;)

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Closed Thread


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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