Sharing a Table Model Between JTable Components

When you share a table model between two table components, any changes made to values in the model will appear in both table components. However, any changes to the visible columns in one table component will not affect the columns in the other table component.
DefaultTableModel model = new DefaultTableModel(); JTable table1 = new JTable(model); JTable table2 = new JTable(model); // Add data here // Place the two tables in a split pane JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitPane.add(new JScrollPane(table1)); splitPane.add(new JScrollPane(table2)); // Remove the first visible column from table1; // the column will not be removed from table2 table1.getColumnModel().removeColumn(table1.getColumnModel().getColumn(0));

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.