File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox and "long" items rendered via HTML

 
Claude Moore
Ranch Hand
Posts: 746
7
IBM DB2 Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Claude Moore
Ranch Hand
Posts: 746
7
IBM DB2 Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need two colours. I insert items which are couples <code, description>, read from database. The "code" part is bold.
 
Rob Camick
Ranch Hand
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 746
7
IBM DB2 Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic