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
tra4d
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Differences between v5.0 OS and v6.0 OS for ObjectChoiceField?

[ Edited ]

Hi

 

I have the following code for a custom choice field.  It works great in v5.0 OS but gives an error "JVM Error 104 Uncaught: IllegalArgumentException".  Any ideas why or what has changed?

 

 

import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.ObjectChoiceField;

public class _fWHChoiceField extends ObjectChoiceField {
		private int setWidth = 0;
		private int setHeight = 0;
		private boolean disabled = false;
		
		public boolean isFocusable() {
	        if(disabled)
	            return false; 
	        return true;
	    } //isFocusable
		
		public void disable() {
	        disabled=true;
	        super.setVisualState(ButtonField.VISUAL_STATE_DISABLED);
	    } //disable
	    
	    public void enable() {
	        disabled=false;        
	        super.setVisualState(ButtonField.VISUAL_STATE_NORMAL);
	    } //enable
		
		public _fWHChoiceField(String text, Object[] choices, long setStyle, int initIndex, int pSetWidth, int pSetHeight) {
			super(text, choices, initIndex, setStyle);
			setWidth = pSetWidth;
			setHeight = pSetHeight;
		} //fWHChoiceField
		
//		public int getPreferredWidth() {
//			return setWidth;
//		} 
//		public int getPreferredHeight() {
//			return setHeight;
//		}
		
		public void getFocusRect(XYRect rect) {        
		  rect.set(getFont().getAdvance(getLabel()), 0, setWidth, setHeight);    
		}

		protected void layout(int width, int height) {
//			int useWidth;
//			int useHeight;
//			
//			useWidth = getPreferredWidth();
//			useHeight = getPreferredHeight();
			
			setExtent(setWidth, setHeight);
			//super.layout(useWidth, useHeight);
			
		} //layout
		
		public void paint(Graphics g) {
		    super.paint(g);
		} //paint
		
} //fWHChoiceField

 

 

Regards,

Scott

Developer
tra4d
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Re: Differences between v5.0 OS and v6.0 OS for ObjectChoiceField?

Anybody?

Developer
tra4d
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Re: Differences between v5.0 OS and v6.0 OS for ObjectChoiceField?

It seems to be the call to setExtent in layout.  When calling super.layout it does not blow/lock up but does not fix the size to the desired height:

 

 

	protected void layout(int width, int height) {
		
		super.layout(setWidth, setHeight);
		
	} //layout

 

When using setExtent to set the height/width, it locks up when debugging on a 6.0 device (in this case a Bold 9780):

 

 

 

	protected void layout(int width, int height) {
		
		setExtent(setWidth, setHeight);
		
	} //layout

 

 

It opens up a tab with a title "GraphicsInternal(Graphics).ropInternal with the text "Source not found".

 

???

Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Differences between v5.0 OS and v6.0 OS for ObjectChoiceField?

Why don't you try super.layout followed by setExtent? super.layout is necessary because otherwise the field doesn't know its size. setExtent only sets that for the manager of the field to properly place it and calculate the position of it and other fields.

 

In other words, super.layout(setWidth, setHeight); followed by setExtent(setWidth, setHeight); is most probably the best course of action. It is weird that just the first call is not sufficient, but it is definitely necessary for all built-in fields.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
tra4d
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Re: Differences between v5.0 OS and v6.0 OS for ObjectChoiceField?

Ok, that's a little better.  We are getting the size correct, but its cutting off the text.

 

If the text is too big to all show in the defined space, i.e:

 

ABCDEFG: This is

some text here.

 

Instead of showing "ABCDEFG: This is", we are getting "some text here".  This was functioning very well in v5.0.  I need to be able to show only the beginning of the text for each entry, but show the entire text when the user is selecting the correct entry.

Developer
jprofitt
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: Differences between v5.0 OS and v6.0 OS for ObjectChoiceField?

You may have to override the paint method if you want to display the text selectively based on user choice

Developer
tra4d
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Re: Differences between v5.0 OS and v6.0 OS for ObjectChoiceField?

You mean calling something else before super.paint(Graphics) or doing the entire painting 'manually'?  The latter is above my skill level but if someone could point me in the right direction I would appreaciate it.

Developer
tra4d
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Re: Differences between v5.0 OS and v6.0 OS for ObjectChoiceField?

Update: when I use the following code in the layout method, it behaves the same in v5 and in v6:

 

 

super.layout(setWidth, setHeight);
setExtent(setWidth, setHeight);

 

Both shorten the text to fit into the alloted space, but they show the end of the text, and not the beginning (with ... at the end) as it did in v5 w/ only calling setExtent.

 

So, how can I get it to show the beginning of the text?