Results 1 to 6 of 6

Thread: Combobox

  1. #1
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Combobox

    Hi,

    I want a ComboBox that gets data from a MySQL table and then I will use the selected value into another table.

    Have tried a little my self... First of all i need to get the data into the combo.
    How is the code for this?

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default Re: Combobox

    So what is your problem?

    Do you know how to use SQL? Do you know how to create a loop to get all the data from the ResultSet?

    Do you know how to hard code data and create a ComboBoxModel?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,199
    Rep Power
    19

    Default Re: Combobox

    Have you decided which GUI toolkit you would like to use for this? AWT? Swing? SWT? JFace? Something else?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Combobox

    I'm using Netbeans as GUI toolkit. Swing combobox
    I know how to use SQL. The problem is the resultset.
    An example would be great.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,199
    Rep Power
    19

    Default Re: Combobox

    NetBeans is an IDE, not a GUI toolkit. If you're using Swing, you would be using JComboBox -- not 'combobox'

    Now answer camickr's question
    Quote Originally Posted by camickr View Post
    Do you know how to hard code data and create a ComboBoxModel?
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Combobox

    Sorry, I have been away for a few days...

    First I have a line of query to the database:
    Java Code:
    public class ComboForm extends javax.swing.JFrame {
        private VectorData vectordata = LedgerTable.SelectAll();
    Actually the connection and query is in its own class...

    Heres the code generated by Netbeans, including one line of custom code:
    Java Code:
     private void initComponents() {
    
            jComboBox1 = new javax.swing.JComboBox();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            jComboBox1.setModel(vectordata.getData());
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(112, 112, 112)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(138, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(83, 83, 83)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(195, Short.MAX_VALUE))
            );
    
            pack();
        }
    The custom line is this one:
    Java Code:
    jComboBox1.setModel(vectordata.getData());
    Hopefully you have enough information to guide me to the correct custom line here...

Similar Threads

  1. combobox
    By dina in forum AWT / Swing
    Replies: 7
    Last Post: 05-11-2011, 05:31 PM
  2. combobox
    By leader in forum New To Java
    Replies: 2
    Last Post: 02-12-2011, 09:30 PM
  3. Problem in combobox
    By santhosh_el in forum AWT / Swing
    Replies: 4
    Last Post: 04-03-2009, 04:01 AM
  4. Need Help combobox
    By kwink in forum AWT / Swing
    Replies: 3
    Last Post: 03-21-2009, 10:05 AM
  5. combobox
    By chandu.v in forum New To Java
    Replies: 2
    Last Post: 07-02-2008, 08:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •