Results 1 to 4 of 4

Thread: Jtable rows

  1. #1
    riddhishah28 is offline Member
    Join Date
    Feb 2011
    Posts
    11
    Rep Power
    0

    Unhappy Jtable rows

    hi,
    I want to insert new rows in JTable at runtime. I have used JTable as component in GUI in Netbeans.
    please help
    Thanks

  2. #2
    Join Date
    Feb 2011
    Location
    Ahmedabad
    Posts
    36
    Rep Power
    0

    Default

    you want to add it run time so use following method of JTable to add columns and rows
    Java Code:
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    
    // Create a couple of columns
    model.addColumn("Col1");
    model.addColumn("Col2");
    
    // Append a row
    model.addRow(new Object[]{"v1", "v2"});
    // there are now 2 rows with 2 columns
    
    // Append a row with fewer values than columns.
    // The left-most fields in the new row are populated
    // with the supplied values (left-to-right) and fields
    // without values are set to null.
    model.addRow(new Object[]{"v1"});
    // there are now 3 rows with 2 columns
    
    // Append a row with more values than columns.
    // The extra values are ignored.
    model.addRow(new Object[]{"v1", "v2", "v3"});
    // there are now 4 rows with 2 columns

  3. #3
    riddhishah28 is offline Member
    Join Date
    Feb 2011
    Posts
    11
    Rep Power
    0

    Question

    Thanks for your valuable time..
    but still it doesnt work..
    i think i have used table component and added columns by right click on table...
    plz help

  4. #4
    riddhishah28 is offline Member
    Join Date
    Feb 2011
    Posts
    11
    Rep Power
    0

Similar Threads

  1. How to Add,Remove Rows in JTable
    By Dinesh_rockz in forum AWT / Swing
    Replies: 2
    Last Post: 02-03-2011, 06:30 AM
  2. Remove Jtable rows
    By anilkumar_vist in forum Advanced Java
    Replies: 2
    Last Post: 09-17-2010, 09:03 AM
  3. Listening rows in JTable ??
    By Stephen Douglas in forum New To Java
    Replies: 2
    Last Post: 04-10-2010, 05:45 PM
  4. Deleting All rows in the JTable
    By surot in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 11:44 AM
  5. display rows in jtable
    By osval in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 09:54 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
  •