Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.
Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg
by mkornatzki » Fri Jul 30, 2010 6:28 am
Hi,
if i do the following the item of the list is not selected:
* i use a JFrame and place a JList somewhere
* set the Model with the editor
* set selectedIndex in PropertyEditor
Code looks like:
- Code: Select all
lst.setSelectedIndex(0);
lst.setModel(new AbstractListModel() {
String[] values = new String[]{"Eins", "Zwei", "Drei"};
public int getSize() {
return values.length;
}
public Object getElementAt(int index) {
return values[index];
}
});
Should be:
- Code: Select all
lst.setModel(new AbstractListModel() {
String[] values = new String[]{"Eins", "Zwei", "Drei"};
public int getSize() {
return values.length;
}
public Object getElementAt(int index) {
return values[index];
}
});
lst.setSelectedIndex(0);
cheers,
michael
-
mkornatzki
-
- Posts: 121
- Joined: Wed Oct 15, 2008 3:57 am
by Eric Clayberg » Sun Aug 01, 2010 7:28 am
This is a good example of the limitations of the Swing JavaBean model and why we provide our own *wbp-component.xml files.
In this case, the setSelectedIndex() and setModel() methods have an implicit order dependency (an unnecessary one, IMO).
In the latest v7.6 build we will now always generate setSelectedIndex() after setModel() (currently, it depends on the order in which the user defines the properties).
-
Eric Clayberg
- Moderator
-
- Posts: 4503
- Joined: Tue Sep 30, 2003 6:39 am
- Location: Boston, MA USA
-
Return to Swing Designer
Who is online
Users browsing this forum: No registered users and 1 guest