Refresh a jTable

后端 未结 1 1457
谎友^
谎友^ 2021-01-28 16:00

I can\'t seem to get my table to refresh. I created a refresh button that calls jTable1.repaint();

private void jButton8ActionPerformed(java.awt.eve         


        
相关标签:
1条回答
  • 2021-01-28 16:37

    Neither

    jTable1.repaint();
    

    or

    RegistryValues.arp(null);
    

    will actually refresh the table with new values. For this you need to either update the current table model or set a new model but in your ActionListener.

    As you're using DefaultTableModel, which is mutable, you could create an update helper method for the model.

    Something like:

    DefaultTableModel model = (DefaultTableModel) table.getModel();
    model.setValueAt(RegistryValues.arp(null), 0, 1);
    // set more row data, etc.
    

    Note: You could save the model as a class member variable and eliminate the need for casting.

    0 讨论(0)
提交回复
热议问题