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

Thread: change JTable column name, gui does not update at once

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question change JTable column name, gui does not update at once

    I use following code to change column name:
      public void ChangeName(JTable table, int col_index, String col_name){
        table.getColumnModel().getColumn(col_index).setHeaderValue(col_name);
      }
    It actually works but in GUI it updates only when I click on column header.
    where could be the problem?
    Last edited by helloworld922; May 22nd, 2011 at 08:14 PM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: change JTable column name, gui does not update at once

    Likely it's because you're not explicitly forcing a repaint.

  3. #3
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,099
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: change JTable column name, gui does not update at once

    You need to notify the model the the table structure has changed. Presuming the TableModel of your JTable extends AbstractTableModel, call fireTableStructureChanged() on the model

  4. #4
    Junior Member
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: change JTable column name, gui does not update at once

    thanks, copeg! your solution worked but it recreated all table from model which contained old data so I had to change approach. now I use model.setColumnIdentifiers(columnNames) each time I need to change columnNames and it works. thanks again.

Similar Threads

  1. [SOLVED] how to get the row and column of a component gridlayout
    By prettynew in forum AWT / Java Swing
    Replies: 0
    Last Post: March 13th, 2011, 06:39 PM
  2. [SOLVED] Quick JTable Column Sort Question
    By aussiemcgr in forum Java Theory & Questions
    Replies: 1
    Last Post: October 15th, 2010, 04:35 PM
  3. Excel Column Letter Referencing
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 21st, 2010, 03:47 PM
  4. Highlighting both row and column in JTable
    By bschneider14 in forum AWT / Java Swing
    Replies: 4
    Last Post: May 29th, 2010, 09:14 AM