• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JComboBox and "long" items rendered via HTML

 
Bartender
Posts: 1359
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1359
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1359
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
reply
    Bookmark Topic Watch Topic
  • New Topic