aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JComboBox display issue when changing models Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JComboBox display issue when changing models" Watch "JComboBox display issue when changing models" New topic
Author

JComboBox display issue when changing models

davidb smith
Greenhorn

Joined: Jul 20, 2011
Posts: 4
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.
//////




[Thumbnail for TestComboProblem.png]

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19757
    
  20

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).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
davidb smith
Greenhorn

Joined: Jul 20, 2011
Posts: 4
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

Joined: Oct 27, 2005
Posts: 19757
    
  20

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JComboBox display issue when changing models