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
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Cursor/Caret not appearing in EditField?

I've debugged Peter's code yesterday at home and it was working great.  The only part I removed was that fillRect() call - clear() is already doing the job.

 

I've added some debug prints and found that drawFocus(g, true), called with clipping rectangle corresponding to the whole field, indeed calls paint() with a clipping rectangle corresponding to just one letter.  So my crazy idea was not so crazy :smileyhappy:

 

Seriously, try Peter's code and ask yourself whether you need anything else.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
New Developer
lisfolks
Posts: 10
Registered: ‎03-23-2010
My Device: Curve 8900

Re: Cursor/Caret not appearing in EditField?

Thanks, peter_strange.  I will do that now.

Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Cursor/Caret not appearing in EditField?

The answer to your question:

"is there a way to paint only the text portion of the field, leaving the label at the default?  Or, will I have to separate the label out to do that?"

is yes.

 

You can easily figure out the size of the Field (using getExtent()).  This will give you a rectangle.  Then you can figure out how big the label is - assuming it is only one line, using

this.getFont().getAdvance(this.getLabel())

was the width and

this.getFont().getHeight() as the height.

So you can figure out the rectangle used by the label.  That is the part you don't want to fill in.  Note that this can mean two fillRect, one for the part to the right of the Label and one for the part below (for multiple line Fields). 

 

From memory, this goes a little squiffy because the Field I think might have a height slightly higher even when there is only one line displayed, but I'm sure you will sort this out. 

Developer
StevenKader
Posts: 644
Registered: ‎02-03-2010
My Device: Z10 LE

Re: Cursor/Caret not appearing in EditField?

Just asking this question since you are new to this.  I'm not sure what happened if you just used the regular EditField with no override.  What are you trying to add to the regular EditField that isn't there already?


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Cursor/Caret not appearing in EditField?

From looking at the code I believe this poster is trying to change the background depending on whether it is in focus or not.

Developer
StevenKader
Posts: 644
Registered: ‎02-03-2010
My Device: Z10 LE

Re: Cursor/Caret not appearing in EditField?

[ Edited ]

Hi Peter,  I thought about that until I saw the poster write this :

 

"the only reason I'm changing the background color on focus/unfocus is because of the missing cursor.  I do want a background color, but I would leave it alone if he caret would appear properly. "

 

It looks like he added that to try and get the cursor to show up and could do without it.

 

It could be that he just needed to add the style EditField.FOCUSABLE to make sure his editfield was getting focus which should show the cursor at some point before all of this extra code.


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing
New Developer
lisfolks
Posts: 10
Registered: ‎03-23-2010
My Device: Curve 8900

Re: Cursor/Caret not appearing in EditField?

Thanks, all!  peter_strange's code did the trick, so I will mark his as the solution.

 

Yes, I was initially trying to change the background color to indicate that the EditField's content (text) area had focus.  I actually hadn't realized that the cursor was missing!  I just wanted an easy way for the user to tell where they could enter text.

 

Once I realized the cursor was missing, then I realized that the user would be able to tell where to enter the text if the cursor was present - and it would be nice if I understood why, exactly, the cursor had gone missing - so I extended my question.

 

peter_strange, the drawFocus override did the trick to make the cursor appear.  I also removed the rectFill, as arkadyz suggested, when I found it wasn't doing anything really.  The rest of the paint override did the trick with the background coloring, so now I have both that and the cursor showing as it should.

 

As to Jaredco's question about what I was doing with the EditField that wasn't there - well, my original goal was simply to change the width of the EditField.  It defaults to full width, so was knocking a following field off the display.  I had thought that if I overrode the layout method, I also had to override the paint method, so I had done so without testing just the layout change alone.  Then I saw there was no easy way for the user to tell that they could begin typing there - uh, missing cursor and "messy" paint override :smileywink:

 

Thanks again for the help (and time!) you all have given me in resolving this issue.  I learned a lot!

New Developer
AbdurRahim
Posts: 32
Registered: ‎11-02-2009
My Device: Not Specified

Check Spelling making color text black

I have a custom TextBoxField. When i select Check Spelling from menu to check spelling. then it makes the color red and when i select correct from the suggested words then it makes the text color black. then the text is invisible in my field because i already set backgroung color black.

 

public class TextBoxField extends Manager
{
    private int firstTime = 0;
    //define some variables to be used
    //in the class
    private int managerWidth;
    private int managerHeight;
    private EditField editField;
    private VerticalScrollManager verticalFieldManager;

    public TextBoxField(int width, int height)
    {
        super(Manager.NO_VERTICAL_SCROLL | Manager.FOCUSABLE);
        managerWidth = width;
        managerHeight = height;
        verticalFieldManager = new VerticalScrollManager(Manager.VERTICAL_SCROLL
                | Manager.VERTICAL_SCROLLBAR | FOCUSABLE)
        {
            protected void sublayout(int maxWidth, int maxHeight)
            {
                super.sublayout(managerWidth, managerHeight);
                setExtent(managerWidth, managerHeight);
            }

        };
        

        
        editField = new EditField(EDITABLE| EditField.FOCUSABLE){
            public void paint(Graphics g) {
                getManager().invalidate();
                super.paint(g);
            }
            protected void layout(int width, int height) {
                super.layout(width, height);
                
                if(managerHeight > this.getHeight()){
                    setExtent(width, managerHeight);
                }
            }
        };

        verticalFieldManager.add(editField);
        add(verticalFieldManager);
    }
    
    public void paint(Graphics graphics)
    {
        int orignalColor = graphics.getColor();
        graphics.setColor(Color.WHITE);
        super.paint(graphics);
        graphics.setColor(orignalColor);

        super.paint(graphics);
        graphics.drawRect(0, 0, getWidth(), getHeight());
    }
    /*
    public void sublayout(int width, int height) {
        if (managerWidth == 0) {
            managerWidth = width;
        }
        if (managerHeight == 0) {
            managerHeight = height;
        }
        
        layoutChild(verticalFieldManager, width, height);
        setPositionChild(verticalFieldManager, managerWidth,
                managerHeight);

//        super.sublayout(managerWidth, managerHeight);
        setExtent(managerWidth,managerHeight);
    }
    */
    public String getText() {
        return editField.getText();
    }
    
    public void setText(String text) {
        editField.setText(text);
    }

    protected void sublayout(int width, int height)
    {
        layoutChild(verticalFieldManager, width, height);
        setPositionChild(verticalFieldManager, 0,
                0);

         setExtent(managerWidth, managerHeight);
        
    }
    
    public void paintBackground(Graphics graphics)
    {
        int originalColor = graphics.getColor();
        graphics.setColor(Color.BLACK);
        graphics.fillRect(0, 0, this.getWidth(), this.getHeight());
        graphics.setColor(originalColor);
    }
    
    protected boolean navigationClick(int status, int time) {
        if ((status & KeypadListener.STATUS_ALT) == 0 &&
                (status & KeypadListener.STATUS_SHIFT) == 0)
        {
            editField.setFocus();
        }
        return super.navigationClick(status, time);
    }

    protected void onFocus(int direction) {

        super.onFocus(direction);
    }

}

New Contributor
kinjalshah_5320
Posts: 9
Registered: ‎07-02-2012
My Device: blackberry 9930,9900

Re: Cursor/Caret not appearing in EditField?

Hey i also get the same problem..Cursor is not appearing in Editfield..

 

Following is the code..

 

ef_mob = new EditField("", "", 11, EditField.NO_NEWLINE|EditField.FILTER_NUMERIC|EditField.FOCUSABLE) {
            protected void paint(Graphics graphics) {
                // TODO Auto-generated method stub
                graphics.setColor(Color.WHITE);
                graphics.drawRoundRect(0, 0, getWidth()-(getWidth()/10), getHeight(), 5, 5);
                
                graphics.fillRoundRect(0, 0, getWidth()-(getWidth()/10), getHeight(), 5, 5);
                graphics.setColor(Color.BLACK);
                super.paint(graphics);
            }
            
            

        };

 

what is the problem??plz guide me....thanks ..

Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Cursor/Caret not appearing in EditField?

Have you updated the code as per the solution to this Thread?

http://supportforums.blackberry.com/t5/Java-Development/Cursor-Caret-not-appearing-in-EditField/m-p/...

 

If not, have a look at that code and incorporate the changes in your code, especially the drawFocus changes.  .

 

If this does not work, please start a new Thread.  You can reference this Thread if you think it provides useful information.  But you normally don't add to a solved Thread - people don;t look at solved Threads unless they are looking for a solution.