Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're right - you shouldn't need to re-construct the <code>JPanel</code>. Indeed, you shouldn't even need to reconstruct the <code>JTable</code>, or possibly even the <code>TableModel</code>. (Also, you might want to do some reading about the Model-View-Controller design pattern)</p> <p>Instead, you should be resetting the data in the <code>TableModel</code>. I think this should cause the <code>JTable</code> to be repainted. If not, you could call:</p> <pre><code>table.tableChanged(new TableModelEvent(tableModel)); </code></pre> <p>Alternatively, if you feel it's better to construct a new <code>TableModel</code> with the new data:</p> <pre><code>table.setModel(newTableModel); </code></pre> <p>Here's an <a href="http://www.sscce.org/" rel="nofollow">SSCCE</a> of a <code>JTable</code> that is updated by something else... I've replaced the database connection with input from a <code>JTextField</code>, but it should give you the idea:</p> <pre><code>public class TableTest { public static void main(String[] args) { JFrame frame = new JFrame("Table Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTextField text = new JTextField("Editable Text"); final TableModel model = new DefaultTableModel(new String[]{"Text"},1); model.setValueAt(text.getText(), 0, 0); text.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { model.setValueAt(text.getText(), 0, 0); } }); JTable table = new JTable(model); JPanel panel = new JPanel(new BorderLayout()); panel.add(text, BorderLayout.NORTH); panel.add(new JScrollPane(table), BorderLayout.SOUTH); frame.setContentPane(panel); frame.pack(); frame.setVisible(true); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload