How do I modify the titles of a jTable in Java runtime?

0

I have the following table:

    String x[][]={};
    String columns[]= {"Programa","Estudiante","Modalidad"};
    model = new DefaultTableModel(x,columns);
    table.setModel(model);

And I would like to modify the titles of this table, which are the ones that are in columns during the execution of the program, they could help me.

    
asked by Mengano 13.10.2018 в 00:57
source

1 answer

1

This change during the runtime can be achieved using a TableColumn with which it is possible to modify the information via setHeaderValue(String) , assuming that a method is available for this task:

private void updateHeader() {
  javax.swing.table.TableColumn TC;
  for(int i=0; i<table.getColumnCount(); i++) {
    TC = table.getTableHeader().getColumnModel().getColumn(i);
    TC.setHeaderValue("Titulo "+(i+1));
  }
}

In line 4 basically the column is removed from the header of the table and finally we proceed to modify the data with the method setHeaderValue previously mentioned.

    
answered by 13.10.2018 / 03:07
source