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 3 of 3

Thread: remove a colum from a DefaultTableModel

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default remove a colum from a DefaultTableModel

    hi everyone, I have a DefaultTableModel that I built with tableModel.addColumn("dasdasfasfs"), thereafter I fill it with addRow.
    I want to reuse the tableModel, but before I want to clear it (rows and columns) to add different columns and different rows.

    for the rows:
    for (int i = 0; i < this.tableModel.getRowCount(); i++) {
    this.tableModel.removeRow(i);
    }

    but don't know how to remove the columns

    thanks


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: remove a colum from a DefaultTableModel

    There are methods that set the column identifiers (setColumnIdentifiers(...)), which replace the current identifiers. Why not just instantiate a new instance?

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: remove a colum from a DefaultTableModel

    ok problem solved, use setColumnIdentifiers better than addColumn, it just replace columns, thanks copeg!

Similar Threads

  1. DefaultTableModel Serialization
    By newbie in forum Java Theory & Questions
    Replies: 8
    Last Post: August 15th, 2011, 07:46 PM
  2. How to remove the last comma
    By fride360 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 29th, 2011, 07:20 AM
  3. not able to remove from ArrayList
    By harsha_c in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 3rd, 2011, 03:28 AM
  4. Writing data to the java DefaultTableModel
    By dubois.ford in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 1st, 2010, 08:43 PM
  5. How to remove letters
    By noobish in forum Java Theory & Questions
    Replies: 13
    Last Post: October 3rd, 2009, 10:36 PM