• 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 display issue when changing models

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having a display issue when changing list elements within a model that is attached to a JComboBox. Using the attached code, perform the following:

launch code.
click on button "list2"
select any element in the Combobox.
click on button "list1".
try to select an element in the combobox.

the popup display is of the correct length, but the list is empty.

THis problem occurs when selecting an element from a smaller list as the FIRST ACTION. If I select from a longer list first (click on list one and select anythingthen go to list 2) this behavior does not appear.


I am on a Macintosh running Snow Leopard (10.6) and using Java 1.6.0

Any ideas?

Thanks

I have attached a screen shot showing the issue as well as placing code in the body of the text.
//////

TestComboProblem.png
[Thumbnail for TestComboProblem.png]
Screen shot showing problem
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're ComboBoxModel implementation needs to fire the appropriate events to any ListDataListener that's added to it. The JComboBox adds at least one such listener itself. So:
- keep a List of ListDataListener objects that you modify from the addListDataListener and removeListDataListener methods.
- in the setList method, you first call intervalRemoved with 0 and the old size - 1 as the bounds (skipping if the old size is 0), then intervalAdded with 0 and the new size - 1 as the bounds (skipping if the new size is 0).
 
davidb smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok that worked! The code I had sent was a simplified example of the behavior I was using in a more complex application, and I had not included the implementation of the add and remove listener methods. What I had not done was do the ListDataEvent explicit updating. Instead of using the intervalDeleted and intervalAdded I used a single CONTENTS_CHANGED event and that seemed to work fine. Do you see any issues with that? Basically I change the editList to this:


So thanks again!
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't suggest contentsChanged because I didn't know what to use for the indexes, but apparently 0 and -1 work. And you're welcome
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic