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: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: In the EditField...

 

/** * The sentinal sample! * * Copyright ¬ 1998-2007 Research In Motion Ltd. */ package com.rim.samples.device.helloworld; import com.rim.samples.device.resource.*; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.i18n.*; import net.rim.device.api.system.*; import net.rim.device.api.collection.util.*; /** * <p>The HelloWorld sample demonstrates some of the most basic features * of the RIM UI and internationalization (i18n). */ public class HelloWorld extends UiApplication { //statics ------------------------------------------------------------------ public static void main(String[] args) { HelloWorld theApp = new HelloWorld(); //To make the application enter the event thread and start processing messages, we invoke the enterEventDispatcher method theApp.enterEventDispatcher(); } /** * <p>the default constructor. Creates all the RIM UI components and pushes the application's root screen onto the UI stack */ public HelloWorld() { //Push the main screen instance onto the UI stack for rendering. pushScreen(new HelloWorldScreen()); } } /*package*/ final class HelloWorldScreen extends MainScreen implements HelloWorldResResource { //members ------------------------------------------------------------------ /** * <p>It is RIM recommended practice that you internationalize your code from the * beginning. In order to do so, you'll need to create an RRH file, and various * RRC files, one for each language or dialect you intend to support. * Review the associated RRH and RRC files included with this project. Notice * that the HelloWorld class implements a resouce interface. That interface * is automatically generated from the RRH file. */ private static ResourceBundle _resources = ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME); /** * Add the title and a simple richtext field */ public HelloWorldScreen() { super(DEFAULT_MENU | DEFAULT_CLOSE); //Add a field to the title region of the screen. We use a simple LabelField here. The ELLIPSIS option truncates // the label text with "..." if the text was too long for the space available. setTitle(new LabelField(_resources.getString(HELLOWORLD_TITLE), LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH)); //Add a read only text field (RichTextField) to the field portion of the screen. The RTF is focusable by default. add(new RichTextField(_resources.getString(HELLOWORLD_CONTENTSTRING))); LabelField optLabel2 = new LabelField("Option #2:", LabelField.FIELD_HCENTER) { protected void layout(int maxWidth, int maxHeight) { super.layout(Display.getWidth()-20, this.getHeight()); setExtent(Display.getWidth()-20, this.getHeight()); } }; VerticalFieldManager bodyMgr = new VerticalFieldManager( Manager.VERTICAL_SCROLL|Manager.FIELD_HCENTER| VerticalFieldManager.VERTICAL_SCROLLBAR) { protected void sublayout(int maxWidth, int maxHeight) { super.sublayout(Display.getWidth(), Display.getHeight()-25); setExtent(maxWidth, maxHeight-25); } }; VerticalFieldManager subVmgr2 = new VerticalFieldManager( VerticalFieldManager.NO_VERTICAL_SCROLL| VerticalFieldManager.FIELD_HCENTER| VerticalFieldManager.NO_HORIZONTAL_SCROLL | VerticalFieldManager.VERTICAL_SCROLLBAR|VerticalFieldManager.USE_ALL_WIDTH) { protected void paint(Graphics g) { if (g.getBackgroundColor() != 3098850) { XYRect xy = g.getClippingRect(); g.setBackgroundColor(0xfafafa); g.fillRect(xy.x,xy.y,xy.width,xy.height+10); g.clear(); } super.paint(g); } }; AutoTextEditField opt2Field = new AutoTextEditField ("", "Option message", 256, AutoTextEditField.FIELD_HCENTER) { public void paint(Graphics g) { String str = "Option #2: "; Font _font = Font.getDefault(); int x = _font.getAdvance(str); if (g.getBackgroundColor() != 3098850) { XYRect xy = g.getClippingRect(); g.setBackgroundColor(0xfafafa); g.fillRect(xy.x,xy.y,xy.width,xy.height); g.clear(); } g.setColor(0x333333); g.drawRect(0,0,this.getWidth(), this.getHeight()); System.out.println("this.getWidth()->" + this.getWidth() + ", this.getHeight()->" + this.getHeight()); g.setColor(0x4fb3cc); super.paint(g); } protected void layout(int maxWidth, int maxHeight) { super.layout(Display.getWidth()-20, this.getHeight()); setExtent(Display.getWidth()-20, this.getHeight()); } }; LabelField rspLabel2 = new LabelField("Response #2: ", LabelField.FIELD_HCENTER) { protected void layout(int maxWidth, int maxHeight) { super.layout(Display.getWidth()-20, this.getHeight()); setExtent(Display.getWidth()-20, this.getHeight()); } }; AutoTextEditField rsp2Field = new AutoTextEditField ("", "test gfgf", 256, AutoTextEditField.FIELD_HCENTER) { public void paint(Graphics g) { String str = "Response #2: "; Font _font = Font.getDefault(); int x = _font.getAdvance(this.getText()); if (g.getBackgroundColor() != 3098850) { XYRect xy = g.getClippingRect(); g.setBackgroundColor(0xfafafa); g.fillRect(xy.x,xy.y,xy.width,xy.height); g.clear(); } g.setColor(0x333333); g.drawRect(0,0,this.getWidth(), this.getHeight()); g.setColor(0x4fb3cc); super.paint(g); } protected void layout(int maxWidth, int maxHeight) { super.layout(Display.getWidth()-20, this.getHeight()); setExtent(Display.getWidth()-20, this.getHeight()); } }; subVmgr2.add(optLabel2); subVmgr2.add(opt2Field); subVmgr2.add(rspLabel2); subVmgr2.add(rsp2Field); subVmgr2.add(new LabelField("", LabelField.NON_FOCUSABLE)); bodyMgr.add(subVmgr2); add (bodyMgr); } public boolean onClose() { Dialog.alert(_resources.getString(HELLOWORLD_EXITSTRING)); System.exit(0); return true; } public boolean keyChar(char key, int status, int time) { //intercept the ESC key - exit the app on its receipt boolean retval = false; switch (key) { case Characters.ESCAPE: onClose(); retval = true; break; } return retval; } }

I  pasted my code  to helloworld and tried but same thing happened to me.

 

Please let me know what is wrong.

 

Thanks,

DK.

BlackBerry Development Advisor
Posts: 15,753
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: In the EditField...

This sample is different than the field you posted earlier.  The issue lies in the clear call inside the if block that checks the background colour.  This call in combination with the change of background colour is overwriting the cursor.  Removing the clear call allows the cursor to be drawn.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: In the EditField...

Mark,

First of all, I'm sorry the ugly code. I was doing kind of cut & paste  of my code.

I removed clear() from the if block and I was able to see the cursor but the problem is the box color becomes black.

 

Any clues for that.

 

Thanks,

DK.

BlackBerry Development Advisor
Posts: 15,753
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: In the EditField...

The g.fillRect call is drawing the black square.  If you want this drawn in another color you'll need to use setColor before this call, not setBackgroundColor.  The current color you are drawing in is black.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Posts: 11
Registered: ‎04-15-2009
My Device: Not Specified

Re: In the EditField...

The problem in a nutshell is:

 

In the following configuration, you see the cursor but the background is black:

 

public void paint(Graphics g)
            {
                XYRect xy = g.getClippingRect();
                g.fillRect(xy.x,xy.y,xy.width,xy.height);
                g.setColor(0x666666);
                super.paint(g);
            }

 

When you set the color to ANYTHING, the cursor disappears, but the rectangle is filled:

 

public void paint(Graphics g)
            {
                XYRect xy = g.getClippingRect();
                g.setColor(0xcccccc);
                g.fillRect(xy.x,xy.y,xy.width,xy.height);
                g.setColor(0x666666);
                super.paint(g);
            }

 

I think what the previous gentleman was asking was: can one have a filled rectangle and also a visible cursor?

 

I would appreciate any wisdom in this area.

 

Thank you,

 

-Rob.

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: In the EditField...

Try painting the background in the manager, rather than the field.

 

New Developer
Posts: 28
Registered: ‎05-27-2009
My Device: Not Specified

Re: In the EditField...

I tried adding the background to the manager and that worked - but now two things happen:

 

1) Without any paint methods to each text field, the background of each link turns white when you hover over them.

2) With a paint method, you lose the cursor when you scroll over whatever field has the link.

 

How do you set something up so that you don't get the background AND you can see the cursor?

 

It's absurd that you can't simply add a hyperlink and be done with it.

New Developer
Posts: 15
Registered: ‎11-08-2008
My Device: 8330 Curve

Re: In the EditField...

I'm going through the same problem although my code is slightly different.  Everybody keeps referring me to this thread to see about redrawing the cursor but I am not seeing it.  Is there a way to redraw the cursor from you own custom class or anything similar.  I really like the way I skinned my app and do not want to change it back to plain white just because a silly (yet needed) cursor will not show up.
Developer
Posts: 176
Registered: ‎11-06-2008
My Device: Not Specified

Re: In the EditField...

I really have no idea if this solves your problem MourningWood but here's some caret drawing code I found in a sample somewhere a while ago

 

 

protected void paint(Graphics graphics) { super.paint(graphics); // Draw caret. getFocusRect(new XYRect()); drawFocus(graphics, true); }

 

 

 

Highlighted
New Developer
Posts: 15
Registered: ‎11-08-2008
My Device: 8330 Curve

Re: In the EditField...

Thank you for the reply but I'm not sure I know how or where to use that.  I'm going to play with it a little later today to see if I can make it work.  I'll let you know how it goes.