Dynamic loading of a JComboBox

B

bruce

I'm trying to load a JComboBox from my database. Here is
the scenario that I am using. The JComboBox is NOT being
loaded correctly so, obviously, I'm doing something wrong.
Appreciate some help.

Scenario:

1. Place a JComboBox on a JFrame.
2. Right Click on the JComboBox.
3. Select "Bind" and Click on "elements".
4. Click "Import Data to Form..."
5. Select the database connection to use. [I have the correct
connection set up]
6. Select the table to use.
7. Run the project.
The JComboBox is filled with two items:
Census.Places[placesid=1]
Census.Places[placesid=2]

> My package is "Census"
> NetBeans created is class "Places" that seems to contain code to
handle this dynamic loading.
> My database contains two fields: placeid and place
> Primary Key is placeid, datafield is place.
> There are two records in the database.

So, it looks like I'm close but not close enough!!!

Appreciate any suggestions on what I'm doing wrong and what I need to
get this working.

Thanks...

Bruce
 
B

bruce

I'm trying to load a JComboBox from my database. Here is
the scenario that I am using. The JComboBox is NOT being
loaded correctly so, obviously, I'm doing something wrong.
Appreciate some help.

Scenario:

1. Place a JComboBox on a JFrame.
2. Right Click on the JComboBox.
3. Select "Bind" and Click on "elements".
4. Click "Import Data to Form..."
5. Select the database connection to use. [I have the correct
connection set up]
6. Select the table to use.
7. Run the project.
        The JComboBox is filled with two items:
        Census.Places[placesid=1]
        Census.Places[placesid=2]

        > My package is "Census"
        > NetBeans created is class "Places" that seems to contain code to
handle this dynamic loading.
        > My database contains two fields: placeid and place
        > Primary Key is placeid, datafield is place.
        > There are two records in the database.

So, it looks like I'm close but not close enough!!!

Appreciate any suggestions on what I'm doing wrong and what I need to
get this working.

Thanks...

Bruce

Can anyone suggest what I'm doing wrong. The above note is the
scenario I'm using.

Thanks....

Bruce
 
I

Ian Shef

I'm trying to load a JComboBox from my database. Here is
the scenario that I am using. The JComboBox is NOT being
loaded correctly so, obviously, I'm doing something wrong.
Appreciate some help.

Scenario:

1. Place a JComboBox on a JFrame.
2. Right Click on the JComboBox.
3. Select "Bind" and Click on "elements".
4. Click "Import Data to Form..."
5. Select the database connection to use. [I have the correct
connection set up]
6. Select the table to use.
7. Run the project.
        The JComboBox is filled with two items:
        Census.Places[placesid=1]
        Census.Places[placesid=2]

        > My package is "Census"
        > NetBeans created is class "Places" that seems to contai n code to
handle this dynamic loading.
        > My database contains two fields: placeid and place
        > Primary Key is placeid, datafield is place.
        > There are two records in the database.

So, it looks like I'm close but not close enough!!!

Appreciate any suggestions on what I'm doing wrong and what I need to
get this working.

Thanks...

Bruce

Can anyone suggest what I'm doing wrong. The above note is the
scenario I'm using.

Thanks....

Bruce

From

http://download.oracle.com/javase/tutorial/uiswing/components/combobox.html

"The default renderer knows how to render strings and icons. If you put
other objects in a combo box, the default renderer calls the toString
method to provide a string to display. You can customize the way a combo
box renders itself and its items by implementing your own ListCellRenderer.
"

Notice that if you don't do anything special, and if your objects are not
String or Icon, then toString() will be used to display your objects.

It looks to me like you need to change Places#toString(), or specify a
different renderer for your JComboBox.

Perhaps someone can help if you would explain what IDE you are using.
 
B

bruce

 >>>          >  NetBeans created is class "Places" that seems to contai

I'm guessing "NetBeans."

Yes, the IDE is NetBeans, 6.9.1.

Thanks for the response.

Bruce
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top