Skip to main content



      Home
Home » Archived » Visual Editor (VE) » Visually adding list members to a JComboBox
Visually adding list members to a JComboBox [message #114183] Fri, 23 December 2005 14:46 Go to next message
Eclipse UserFriend
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
Re: Visually adding list members to a JComboBox [message #114290 is a reply to message #114183] Wed, 28 December 2005 23:10 Go to previous messageGo to next message
Eclipse UserFriend
Rich,

Unfortunately yes, the VE does not currently have support for dealing
with models such as the one for a JComboBox outside their Java Bean
properties. So you were correct in adding the code to add the elements
by hand.

- Jeff
Re: Visually adding list members to a JComboBox [message #114303 is a reply to message #114290] Wed, 28 December 2005 23:28 Go to previous message
Eclipse UserFriend
Originally posted by: rick_w_55075.yahoo.com

Thanks. It's good to have the right expectations, so I appreciate the
answer and will work around it when it comes up again.
Re: Visually adding list members to a JComboBox [message #611706 is a reply to message #114183] Wed, 28 December 2005 23:10 Go to previous message
Eclipse UserFriend
Rich,

Unfortunately yes, the VE does not currently have support for dealing
with models such as the one for a JComboBox outside their Java Bean
properties. So you were correct in adding the code to add the elements
by hand.

- Jeff
Re: Visually adding list members to a JComboBox [message #611707 is a reply to message #114290] Wed, 28 December 2005 23:28 Go to previous message
Eclipse UserFriend
Originally posted by: rick_w_55075.yahoo.com

Thanks. It's good to have the right expectations, so I appreciate the
answer and will work around it when it comes up again.
Previous Topic:Error when create a application by VE
Next Topic:Tables
Goto Forum:
  


Current Time: Wed May 07 17:52:59 EDT 2025

Powered by FUDForum. Page generated in 0.04802 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top