Skip to main content

Alignment within a list or combobox

7 replies [Last post]
mmc2
Offline
Joined: 2010-02-09
Points: 0

I would like to use a list and/or a combobox to display a list of items each having a text and a numeric component, joined into one. I would like the numeric component right justified. I could do this manually if I could get Font.substringWidth() to work.
eg System.out.println(Font.substringWidth(s, 0, 10));, but I get an error message.
I can't simply count spaces as the target handset has a default proportional font.
Alternatively I could have two lists side by side with one disabled from taking focus, but I cannot get rid of the background focus colour for the second list for the first entry.

Any help really appreciated

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mmc2
Offline
Joined: 2010-02-09
Points: 0

myinstinct Thank you for your help

mmc2
Offline
Joined: 2010-02-09
Points: 0

Thank you for your help

mmc2
Offline
Joined: 2010-02-09
Points: 0

Thanks for your interest

if I use System.out.println(Font.substringWidth(s, 1, 10)); I get a message that the non static method cannot be referenced from a static context.

if I use System.out.println(font.substringWidth(s, 1, 10)); I get a message cannot find Symbol: method substringWidth(Java.lang.String,int,int)
Location: class MMC_Package.font

myinstinct
Offline
Joined: 2008-10-24
Points: 0

try something like

[code]
Font myFont = Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
int mySubStrWidth = myFont.substringWidth(s, 1, 10);
[/code]

instead of createSystemFont use whatever you need -
[code]createBitmapFont(...) or getBitmapFont(...) etc[/code]

the key is to call substringWidth from the font you are using

HTH

Mixa

yep, it seems to be a basic java language question of a newbe.

mmc2 - probably you need to read some basic java language books and
simple examples. Our answer may be even less useful than reading a
good java book ;)

Consider using of an IDE for writing java code, such as Eclipse (I
use), Netbeans (from Sun, often goes preinstalled in Sun JDK) or Idea.
They have syntax highlighting and error correction options - may be
useful for you.

Mike

On Thu, Mar 25, 2010 at 5:23 AM, wrote:
> try something like
>
> [code]
> Font myFont = Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
> myFont.substringWidth(s, 1, 10);
> [/code]
>
> instead of createSystemFont use whatever you need -
> [code]createBitmapFont(...) or getBitmapFont(...) etc[/code]
>
> the key is to call substringWidth from the font you are using
>
> HTH
> [Message sent by forum member 'myinstinct']
>
> http://forums.java.net/jive/thread.jspa?messageID=393607
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

mmc2
Offline
Joined: 2010-02-09
Points: 0

Mixa thank you for your help and suggestions. I have read a few Java books and I am using Netbeans. I have also used Eclipse to learn Android. The trouble is, I am a procedural programmer from way back, and although I have achieved a reasonable working knowledge of JME (for some reason I preferred the name J2ME) , OOP is a concept that all my instincts want to reject, and occasionally, as with this situation, the gaps in my knowledge shine through. Thanks once again.

Mixa

Hi,

Did you try bit with bitmap or system fonts? What error message did
you get? May be 10 is bigger than the string length or whatever?

Mike

On Wed, Mar 24, 2010 at 9:11 AM, wrote:
> I would like to use a list and/or a combobox to display a list of items each having a text and a numeric component, joined into one.  I would like the numeric component right justified. I could do this manually if I could get Font.substringWidth() to work.
> eg  System.out.println(Font.substringWidth(s, 0, 10));, but I get an error message.
> I can't simply count spaces as the target handset has a default proportional font.
> Alternatively I could have two lists side by side with one disabled from taking focus, but I cannot get rid of the background focus colour for the second list for the first entry.
>
> Any help really appreciated
> [Message sent by forum member 'mmc2']
>
> http://forums.java.net/jive/thread.jspa?messageID=393407
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net