Visually adding list members to a JComboBox [message #114183] |
Fri, 23 December 2005 14:46  |
Eclipse User |
|
|
|
Originally posted by: rick_w_55075.yahoo.com
First off, congratulations to all the folks working on VE - I'm loving it
because I bought VisualCafe several years ago for a product I sell and
they stopped supporting it for a couple of years now - and VE is a fine
replacement!
My question:
I'm porting my VisualCafe program over, I've been at it for a day or so,
and I'm not sure if what I am seeing regarding models (like ComboBox
models) is the expected behavior within the VE tool. I'm trying to setup a
JComboBox to have two strings in it, let's just say "cat" and "dog".
VisualCafe provided a visual way to add the two strings to the model. Does
VE?
I found a way to create a new model from the defaultComboBoxModel with the
"Properties editor". (I'm not sure if I did it right, but I do see the new
model name in the "Properties editor".) I didn't see any way to add the
strings though. I added them manually to the "getXXX" that VE
automatically generates. The code looks like the following. ("cat" is
really "Search description" and "dog" is really "Search author".)
/**
* This method initializes searchByComboBoxModel
*
* @return javax.swing.DefaultComboBoxModel
*/
private DefaultComboBoxModel getSearchByComboBoxModel() {
if (searchByComboBoxModel == null) {
searchByComboBoxModel = new DefaultComboBoxModel();
searchByComboBoxModel.addElement("Search description");
searchByComboBoxModel.addElement("Search author");
}
return searchByComboBoxModel;
}
After I did this I was hoping the "Properties editor" would see them and
allow me to "setSelectedIndex" to one of them. I tried typing a "0" into
the editor (to select "Search description"). It let me do so but then it
didn't keep my 0. I worked around this by adding the setSelectedIndex line
to the other "getXXX" code that VE generated for the JComboBox. (I moved
where the autogenerated code had put the "setModel" so that it didn't try
to "setSelectedIndex" until after "setModel".)
/**
* This method initializes searchByJComboBox
*
* @return javax.swing.JComboBox
*/
private JComboBox getSearchByJComboBox() {
if (searchByJComboBox == null) {
searchByJComboBox = new JComboBox();
searchByJComboBox.setBounds(new java.awt.Rectangle(531,9,206,29));
searchByJComboBox.setToolTipText("Use to select \"Search by
description\" or \"Search by author\"");
searchByJComboBox.setBorder(javax.swing.BorderFactory.create EtchedBorder(javax.swing.border.EtchedBorder.RAISED));
searchByJComboBox.setModel(getSearchByComboBoxModel());
searchByJComboBox.setSelectedIndex(0);
searchByJComboBox.setFont(new java.awt.Font("Monospaced",
java.awt.Font.BOLD, 12));
}
return searchByJComboBox;
}
The code works. It runs just fine. It's just that I had to do some things
outside the VE. Is this the expected behavior?
Thanks in advance for any light you can shed on my porting challenges,
Rich W
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04802 seconds