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
Posts: 223
Registered: ‎06-08-2010
My Device: pearl8100
My Carrier: airtel

Cursor got invisible/same color of background inside EditField

Hi,

 

My cursor gets hidden inside editfield.I want it to be on visible.How to get it back.Please help me:

 

 

 usernameField = new EditField("",
            "",1000,EditField.FIELD_HCENTER){public void paint(Graphics g) {
                                g.setBackgroundColor(Color.FLORALWHITE);
                                g.clear();
                                super.paint(g);
                                g.drawRect(0,0, getWidth(), getHeight());
                                
                                
                        }
                };

 

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please press the kudos button on the left side to thank the user that helped you.
Trusted Contributor
Posts: 200
Registered: ‎02-22-2010
My Device: BlackBerry 9550
My Carrier: Airtel

Re: Cursor got invisible/same color of background inside EditField

use

 

usernameField.setFocus();

 

this will make the focus at the edit field.

Swapnil G.
Developer
Posts: 223
Registered: ‎06-08-2010
My Device: pearl8100
My Carrier: airtel

Re: Cursor got invisible/same color of background inside EditField

Hi,

 

I am getting error set focus called on field that is not attached to a  screen.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please press the kudos button on the left side to thank the user that helped you.
Highlighted
Developer
Posts: 85
Registered: ‎05-03-2010
My Device: Not Specified

Re: Cursor got invisible/same color of background inside EditField

This question might seem redundant but looking at that error of yours I must ask, have you added your field to the screen or whatever manager you are using?

Developer
Posts: 223
Registered: ‎06-08-2010
My Device: pearl8100
My Carrier: airtel

Re: Cursor got invisible/same color of background inside EditField

Hi,

 

Yes have added to manager.

 // usernameField.setFocus();        
       usernameField.setFont(Font.getDefault().derive(Font.PLAIN));
      
       
        m.add(usernameField);

 

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please press the kudos button on the left side to thank the user that helped you.
Developer
Posts: 106
Registered: ‎06-18-2009
My Device: Bold

Re: Cursor got invisible/same color of background inside EditField

Put the

 

usernameField.setFocus();  

 

at the end of your constructor or where you creating your fields after adding it to your manager and adding the manager to your screen.

 

 

----
If this helped you, press the thumbs up button (on the far right - '+' thumb icon)
If this post solved the issue, click "Accept as Solution"
Developer
Posts: 223
Registered: ‎06-08-2010
My Device: pearl8100
My Carrier: airtel

Re: Cursor got invisible/same color of background inside EditField

Hi filius,

 

As u said i added after adding manager to screen.I didnt get error.But i cant see visible cursor in screen.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please press the kudos button on the left side to thank the user that helped you.
Trusted Contributor
Posts: 200
Registered: ‎02-22-2010
My Device: BlackBerry 9550
My Carrier: Airtel

Re: Cursor got invisible/same color of background inside EditField

		 usernameField = new EditField("",
		            "",1000,EditField.FIELD_HCENTER)
		 {
			 public void paint(Graphics g) 
			 {
				 g.setBackgroundColor(Color.FLORALWHITE);
		         g.clear();
		         super.paint(g);
		         g.drawRect(0,0, getWidth(), getHeight());
		         usernameField.setFocus();
		     }
		  };
		   this.add(usernameField);

 use like this or like the filiusoft suggested....

Swapnil G.
Developer
Posts: 223
Registered: ‎06-08-2010
My Device: pearl8100
My Carrier: airtel

Re: Cursor got invisible/same color of background inside EditField

 

  usernameField = new EditField("",
            "",1000,EditField.FIELD_HCENTER | EditField.NO_NEWLINE ){
                int _bgColor;
                public void onFocus(int direction) {
              _bgColor = Color.BLUE;
                   invalidate();
                  super.onFocus(direction);
           
       }

       public void onUnfocus() {
              super.onUnfocus();
             _bgColor = Color.BLACK;
                invalidate();
       }

                           public void paint(Graphics g) {
                                g.setBackgroundColor(Color.FLORALWHITE);
                                g.clear();
                                super.paint(g);
                                g.setColor(_bgColor);
                                
                                g.drawRect(0,0, getWidth(), getHeight());
                                
                                
                        }
                };
        
       usernameField.setFont(Font.getDefault().derive(Font.PLAIN));
           
        m.add(usernameField);
 manager.add(m);

        add(manager);
         usernameField.setFocus(); 

 

Hi this is how i am using.Since in manager i have background picture.So kept another verticalFieldManager to append in it.But border is visible.Only thing is cursor is not visible

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please press the kudos button on the left side to thank the user that helped you.
Trusted Contributor
Posts: 200
Registered: ‎02-22-2010
My Device: BlackBerry 9550
My Carrier: Airtel

Re: Cursor got invisible/same color of background inside EditField

try to remove

 

g.clear();

from your code.

 

more info i found on this link.

http://supportforums.blackberry.com/t5/Java-Development/Cursor-can-t-be-visible-in-EditField/m-p/398...

 

 

 

 

 

 

please give kudos if you find solution.

Swapnil G.