Results 1 to 11 of 11
  1. #1
    MS-POWER is offline Member
    Join Date
    Oct 2016
    Posts
    24
    Rep Power
    0

    Default JTable into JCombo box

    Dear
    I'm a new in java and I need help

    How To Display JTable reading from database into JCombobox and by selecting item it will be inserted in another Jtable ?

    example :



    thanks

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,983
    Rep Power
    8

    Default Re: JTable into JCombo box

    Take small steps. Do you know how to
    - create a JFrame?
    - create a JTable?
    - create a JComboBox?
    - create a connectionstring for your database?
    - connect to a database?
    - execute a query?
    - iterate through a ResultSet?
    - work with models for JComboBox and JTable?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    MS-POWER is offline Member
    Join Date
    Oct 2016
    Posts
    24
    Rep Power
    0

    Default Re: JTable into JCombo box

    Quote Originally Posted by SurfMan View Post
    Take small steps. Do you know how to
    - create a JFrame?
    - create a JTable?
    - create a JComboBox?
    - create a connectionstring for your database?
    - connect to a database?
    - execute a query?
    - iterate through a ResultSet?
    - work with models for JComboBox and JTable?

    yes I know about all , this Issue and another issue were stopped me from finalizing my DESKTOP APPLICATION project , I created the JFrame designation , and all codes , and I need to apply JTable to JCombobox.

    filling JCombobox with Name or ID is working well but its not professional work , so I need to fill it with ID ,Name and Mobile Number.


    thanks


    thanks
    Last edited by MS-POWER; 10-17-2016 at 03:51 PM.

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,983
    Rep Power
    8

    Default Re: JTable into JCombo box

    Two more questions:
    1) What do you mean by "apply a JTable to a JComboBox"? What would that look like?
    2) If you can fill the JComboBox with Name and ID, what's keeping you from doing the same for Name, ID and Mobile Number?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  5. #5
    MS-POWER is offline Member
    Join Date
    Oct 2016
    Posts
    24
    Rep Power
    0

    Default Re: JTable into JCombo box

    Quote Originally Posted by SurfMan View Post
    Two more questions:
    1) What do you mean by "apply a JTable to a JComboBox"? What would that look like?
    2) If you can fill the JComboBox with Name and ID, what's keeping you from doing the same for Name, ID and Mobile Number?

    thanks dear
    1- I mean to show Jtable in JCombobox dropdown . I think I need some time to learn how to use technical questions and explanation :).

    2- one item in JCombobox is very simple , :

    private void FillComboboxByClient() {
    try {
    String sql = "select* from clients";
    pst = conn.prepareStatement(sql);
    rs = pst.executeQuery();

    while (rs.next()) {

    String r = rs.getString("Client_Number");

    jComboBox4Client.addItem(r);
    }
    } catch (Exception e) {
    JOptionPane.showMessageDialog(null, "Some thing wrong with En_CheckOutToPointOfSale Combo clients");

    } finally {
    try {

    rs.close();
    pst.close();

    } catch (Exception e) {
    }
    }

    }
    ...............

    but for show Jtable in combobox with 3 coulmn need advance work , Im just 5 months self training and two months working on my first Project.


    regards

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: JTable into JCombo box

    You're going to need to read up on cell renderers then.
    These are based of a ListCellRenderer.
    I have no idea if it's possible, but you could play around with:
    Java Code:
    public class TableCellRenderer extends JTable implements ListCellRenderer<something or other> {
    }
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: JTable into JCombo box

    Thinking about it, that won't work as you'll get a table for each cell entry.
    You want a row for each cell...

    You'll have a bit more digging around to do, or come up with something a bit simpler than a bunch of cells within a cell.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,983
    Rep Power
    8

    Default Re: JTable into JCombo box

    I have been playing with a custom ComboBoxEditor. I think that's the way to go. Plenty simple examples of those around, but I can't show an example yet of a ComboBoxEditor with a JTable in it.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: JTable into JCombo box

    Perhaps this is a case where the OP thinks that is what should be done as opposed to other options.

    @OP, please clearly describer your overall goal and how you plan on interacting with this JCombobox.
    BTW, would it work if you combo box had JPanels in it and each panel had the desired table? Another
    possibility is to have a single table but have menu options to dynamically change it to other table types
    depending on the requirement,.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  10. #10
    MS-POWER is offline Member
    Join Date
    Oct 2016
    Posts
    24
    Rep Power
    0

    Default Re: JTable into JCombo box

    thanks a lot for you ,

    the Idea to have more details in Jcombobox to find client if the name match with another client .


    regards

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: JTable into JCombo box

    Looking again at your screenshot, that's going to be one large drop down list.
    I would argue you'd do better with a filter of some sort.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Auto select JCombo box Adding to JTable
    By kasiram.p@gmail.com in forum AWT / Swing
    Replies: 0
    Last Post: 01-03-2011, 06:08 AM
  2. populate jtable from jtextboxes and jcombo
    By purejoker in forum AWT / Swing
    Replies: 4
    Last Post: 12-02-2010, 09:29 AM
  3. AutoSuggest JCombo box
    By vsmilejay in forum AWT / Swing
    Replies: 2
    Last Post: 09-03-2010, 06:34 AM
  4. jcombo in jtable
    By anilkumar_vist in forum Advanced Java
    Replies: 0
    Last Post: 12-12-2009, 06:47 AM
  5. Sort jcombo in jtable
    By anilkumar_vist in forum Advanced Java
    Replies: 1
    Last Post: 12-11-2009, 05:23 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
  •