modify the name of the columns of a jtable from code

0

I have this table in a frame

I have another jframe where when clicking a button the jframe where I have this table changes the names of the columns of the table, this is the code of the table

public void desicionmetodos(int a){
    switch (a){
        case 1:
            Object[] columnNames = {"N","Xn","Yn=Xn^2","Xn+1","Rn+1"};
            DefaultTableModel metodocuadradomedio = (DefaultTableModel) TablaUniversal.getModel();
            metodocuadradomedio.addColumn(columnNames);
            TablaUniversal.setModel(metodocuadradomedio);
            break;
    }
}

but when running it looks like this

    
asked by Efrainrodc 16.05.2017 в 20:09
source

1 answer

1

Try the following code fragment and tell me how it goes:

JTableHeader tableHeader = TablaUniversal.getTableHeader();
TableColumnModel tableColumnModel = tableHeader.getColumnModel();
TableColumn tableColumn = tableColumnModel.getColumn(0);
tableColumn.setHeaderValue( "???" );
tableHeader.repaint();

I hope it serves you Greetings.

    
answered by 16.05.2017 / 21:10
source