Results 1 to 2 of 2
  1. #1
    prad3s4 is offline Member
    Join Date
    Nov 2009
    Rep Power

    Smile How to put a JButton in JTable thrid column?

    can any one plzz help to put a JButton in JTable column

    public class TABLEE extends tablee1 {
    public static void main(String args[]) {
    JFrame frame = new JFrame();
    int i=0;
    DBConnection db=new DBConnection();
    Statement stmt=null;

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    Object row[][] = { };

    JButton btn= new JButton();

    //how to add this btn button in the thrid column

    Object col[] = { "Reference Paper Name", "Author" ,"Link"};
    DefaultTableModel table1=new DefaultTableModel(row,col);
    JTable table = new JTable(table1);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(1000, 750);

    String query="select * from reference where base_id='bp5'";

    PreparedStatement ps=db.getConnection().prepareStatement(query);
    ResultSet rs=ps.executeQuery();


    //how to add this btn button in the thrid column
    table1.insertRow(i,new Object[]{rs.getString(2),rs.getString(3),//Button add here });



  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    Welcome to the Java-Forums. Have you gone through the Sun Swing tutorials on JTables? There is a section that describes using a JButton as a custom cell editor for a JTable: Sun JTable Tutorial. Also, when posting code, please use code tags (please see my signature below).

    Much luck!

Similar Threads

  1. [SOLVED] JSpinner in JTable column
    By nehaa in forum AWT / Swing
    Replies: 10
    Last Post: 05-11-2009, 01:34 PM
  2. Jtable Column Selection Problem
    By REVANSIDDHA in forum Advanced Java
    Replies: 0
    Last Post: 03-31-2009, 07:53 AM
  3. JCheckBox in JTable column
    By hind in forum New To Java
    Replies: 8
    Last Post: 01-04-2009, 07:40 PM
  4. tooltips for JTable column headers
    By fossildoc in forum AWT / Swing
    Replies: 2
    Last Post: 12-18-2008, 11:42 AM
  5. How to sort column in JTable
    By johnt in forum AWT / Swing
    Replies: 3
    Last Post: 06-14-2008, 05:48 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