aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JComboBox and Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JComboBox and "long" items rendered via HTML" Watch "JComboBox and "long" items rendered via HTML" New topic
Author

JComboBox and "long" items rendered via HTML

Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 468
    
    1

Good morning to all,

I need to fill a JComboBox with a list of String items, which are quite long. Now, when the combo box width is shorter than items' size, if I use "regular text" strings
there are no problem: item's text is truncated with ellipses.Instead, if I use "html strings" (I use html to get different colours in displaying items), JComboBox tries
and wraps line..
I'm just wondering if a method exists to achieve truncation even with HTML.

Thanks a lot.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Claude Moore wrote:(I use html to get different colours in displaying items)

Do you need different colors within the same item or just one color for the entire item, with different items in different colors? If the latter, you could use a custom renderer instead of HTML.


luck, db
There are no new questions, but there may be new answers.
Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 468
    
    1

I need two colours. I insert items which are couples <code, description>, read from database. The "code" part is bold.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
I insert items which are couples <code, description>, read from database.


Usually in this case the "code" is not displayed in the combo box since the user generally doesn't care about the code value that is used to access data in the database. So the user would only see the "description". Then when you program gets the selected Item it can access the code value for further processing.

However, if you really want to display both values then here are a couple of other options for displaying a multi column combo box that might help:

Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 468
    
    1

Thank you A LOT for your reply... anyway, i don't want a multi line combo box. I just want to make the combo truncate the description if it's too long to be displayed...
Anyway your code is very precious for me. I'll study it to get advice.

Thanks !
 
jQuery in Action, 2nd edition
 
subject: JComboBox and "long" items rendered via HTML