Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Tolls

Thread: how to embed combobox,checbox in JTable read write to database

  1. #1
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Question how to embed combobox,checbox in JTable read write to database

    Hello everybody, I need to put a combobox in a JTable, and use it to read from DBase and to Insert into DBase.
    Please Help.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: how to embed combobox,checbox in JTable read write to database

    That's nice.
    What have you managed to do so far?
    DarrylBurke likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default Re: how to embed combobox,checbox in JTable read write to database

    This is the code i am using:
    DefaultTableModel model = new DefaultTableModel(new String[]{"Name", "Yes or No","AB"}, 0) {
    public Class<?> getColumnClass(int columnIndex) {
    if (columnIndex == 1) { //If it is the second column
    return Boolean.class;
    }
    else if (columnIndex == 2) { //If it is the second column
    return JComboBox.class;
    }else {
    return Object.class;
    }
    }
    };


    javax.swing.JComboBox box = new JComboBox();
    box.removeAllItems();
    for (int i=0;i<5;i++){
    box.addItem("Name"+(i+1));
    }

    model.addRow(new Object[]{"1", true,"a"});
    model.addRow(new Object[]{"2", false,"a"});
    model.addRow(new Object[]{"3", true,"a"});
    model.addRow(new Object[]{"4", false,box});
    JTable table = new JTable(model);
    The checkbox is working correctly but the combobox doesn't show
    instead a text is shown in the table's cell "javax.swing.JComboBox[,0,3,195x25,invalid,layout=javax.swing.plaf ......"

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: how to embed combobox,checbox in JTable read write to database

    Try the first answer here on StackOverflow (but add in generics).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default Re: how to embed combobox,checbox in JTable read write to database

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

Similar Threads

  1. How to read existing Value from a combobox.
    By Khan05 in forum New To Java
    Replies: 1
    Last Post: 09-20-2011, 04:31 PM
  2. Getting the value from comboBox in Jtable
    By skp123 in forum AWT / Swing
    Replies: 5
    Last Post: 05-16-2011, 01:45 AM
  3. Android read/write to database on a web service.
    By SeanieSortMeOut in forum Android
    Replies: 1
    Last Post: 02-05-2011, 01:21 PM
  4. How to write database queries in Jtable rows and columns?
    By Vignesh Karthick in forum AWT / Swing
    Replies: 1
    Last Post: 02-02-2011, 03:55 PM
  5. add combobox for jtable row
    By anilkumar_vist in forum Advanced Java
    Replies: 1
    Last Post: 11-18-2009, 11:19 AM

Posting Permissions

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