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.


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

Results 1 to 2 of 2

Thread: jTables and models

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

    Unhappy jTables and models

    Hi everyone! I need some help

    I have a jTable that uses a model for handling data

    tableModel = new DefaultTableModel();
    Then, in another class, depending of the class, I erase all the content of the model (and the columns)

    public static void clearDefaultTableModel(DefaultTableModel tableModel) {
    for (int i = 0; i < tableModel.getRowCount(); i++) {
    String[] vector = null;
    When it comes to fill the table, I create the identifiers or columns and insert row by row

    Object[] columnNames = {"header 1","header 2","header 3"};


    String[] vector = {string1,string2,string3};
    What I need is put the jTable not editable (I already changed the seteditable property of the table) and most important, when its time to recreate the model, put differents widths to each column (I dont want the ID column with the same width as the name column)

    Hope you can help me, tables and models are confusing me.

  2. #2
    Join Date
    Oct 2011
    Thanked 3 Times in 3 Posts

    Default Re: jTables and models

    To make the JTable's cells not editable, you need to write your own model class which implements AbstractTableModel, then override the method isCellEditable(), always return false from that method.

    java exception
    Last edited by hns1984; January 11th, 2012 at 06:51 PM.

Similar Threads

  1. [SOLVED] JTables: How do I adjust row order as I drag columns?
    By assel in forum AWT / Java Swing
    Replies: 3
    Last Post: December 7th, 2010, 04:51 PM
  2. JTables with JButtons, I'm overlooking something
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 8th, 2010, 11:30 AM
  3. live feeds and jtables
    By petem86 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: September 19th, 2010, 08:44 PM
  4. Replies: 0
    Last Post: January 26th, 2010, 04:10 PM
  5. set the slider's models (range)
    By chronoz13 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 28th, 2009, 11:59 PM