Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: About deleting rows from table model.

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Location
    Philippines
    Posts
    19
    My Mood
    Dead
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Post About deleting rows from table model.

    How to delete row from the table model without selecting it? The user will just input a number which matches the data from the table?

    example:

    ID | Name | Year |
    ----------------------------------
    1 | Derpina D. | 3rd year |
    ----------------------------------
    2 | Zsannen M. | 2nd Year |
    ----------------------------------

    *The program will ask for an existing ID that will be deleted.

    ENTER ID #: 1

    *Once the user entered a valid ID, all the information about ID #1 will be deleted.

    ID | Name | Year |
    ----------------------------------
    2 | Zsannen M. | 2nd Year |
    ----------------------------------


    *The information is saved to a .txt file. Whenever i input ID number, the information about the entered ID will be deleted on the .txt file. The problem is, only in the GUI, the table, is not being deleted.

    *When deleting, you don't select the row. Instead, you have to input the ID #.


    Would someone help me with this? Thanks in return.
    Badly confused here. I've tried some codes but it doesn't work out.

    THIS IS MY CODE BELOW:

    int select = Integer.valueOf(data.toString());
    int nRow = tableModel.getRowCount();
    Object[] tableData = new Object[nRow];
     
    for (int i = 0 ; i < nRow ; i++){
    tableData[i] = tableModel.getValueAt(i, i);
    //tableModel.removeRow();
    }


  2. #2
    Junior Member
    Join Date
    Nov 2011
    Location
    Aarhus, Denmark
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: About deleting rows from table model.

    Have a look at the javadoc for the DefaultTableModel, it has the needed delete methods. Then you have to create your JTable with your own DefaultTableModel and use that.

    Rolf

Similar Threads

  1. Can anyone suggest me a good tutorial on Abstract Table Model
    By Johnny Bravo in forum AWT / Java Swing
    Replies: 1
    Last Post: August 31st, 2012, 11:16 AM
  2. creating table model....
    By kollyisrealisaac in forum Java Theory & Questions
    Replies: 1
    Last Post: May 6th, 2011, 09:07 AM
  3. Colouring Rows of a table
    By kurt-hardy in forum Java Theory & Questions
    Replies: 5
    Last Post: March 10th, 2011, 08:49 AM
  4. Building Table of Specified Rows and Columns
    By wale89 in forum Java Servlet
    Replies: 1
    Last Post: August 3rd, 2010, 08:57 AM
  5. Need a loop for rows and columns
    By Ceasar in forum Loops & Control Statements
    Replies: 8
    Last Post: October 9th, 2009, 05:47 PM

Tags for this Thread