Dynamic loading of a JComboBox

Discussion in 'Java' started by bruce, Oct 16, 2010.

  1. bruce

    bruce Guest

    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
    bruce, Oct 16, 2010
    #1
    1. Advertising

  2. bruce

    bruce Guest

    On Oct 15, 9:30 pm, bruce <> wrote:
    > 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
    bruce, Oct 18, 2010
    #2
    1. Advertising

  3. bruce

    Ian Shef Guest

    bruce <> wrote in news:72c06022-3dfd-464d-b594-
    :

    > On Oct 15, 9:30 pm, bruce <> wrote:
    >> 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.
    Ian Shef, Oct 18, 2010
    #3
  4. bruce

    markspace Guest

    On 10/18/2010 1:01 PM, Ian Shef wrote:
    > Perhaps someone can help if you would explain what IDE you are using.



    >> On Oct 15, 9:30 pm, bruce<> wrote:
    >>> > NetBeans created is class "Places" that seems to contai



    I'm guessing "NetBeans."
    markspace, Oct 18, 2010
    #4
  5. bruce

    bruce Guest

    On Oct 18, 4:57 pm, markspace <> wrote:
    > On 10/18/2010 1:01 PM, Ian Shef wrote:
    >
    > > Perhaps someone can help if you would explain what IDE you are using.

    >
    >  >> On Oct 15, 9:30 pm, bruce<>  wrote:
    >  >>>          >  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
    bruce, Oct 18, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manoj Nair
    Replies:
    0
    Views:
    1,488
    Manoj Nair
    Sep 12, 2003
  2. Ike

    Objects in a JComboBox

    Ike, Sep 13, 2003, in forum: Java
    Replies:
    3
    Views:
    10,227
  3. HP News Feed
    Replies:
    7
    Views:
    4,428
    Andrew Thompson
    Jul 19, 2005
  4. Ramon F Herrera

    JComboBox with dynamic list?

    Ramon F Herrera, Dec 27, 2005, in forum: Java
    Replies:
    5
    Views:
    28,944
  5. bruce

    Loading a JComboBox

    bruce, Nov 21, 2010, in forum: Java
    Replies:
    11
    Views:
    1,045
    Martin Gregorie
    Nov 23, 2010
Loading...

Share This Page