mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 15:07:11 -06:00
TableHeader: fixed exception when changing table structure (e.g. removing column) from a table header popup menu action (issue #532)
This commit is contained in:
@@ -106,6 +106,20 @@ public class FlatComponents2Test
|
||||
table1.setModel( tableModel );
|
||||
xTable1.setModel( tableModel );
|
||||
|
||||
// table header popup menu
|
||||
JMenuItem addMenuItem = new JMenuItem( "Add column" );
|
||||
addMenuItem.addActionListener( e -> {
|
||||
tableModel.setColumnCount( tableModel.getColumnCount() + 1 );
|
||||
});
|
||||
JMenuItem removeMenuItem = new JMenuItem( "Remove last column" );
|
||||
removeMenuItem.addActionListener( e -> {
|
||||
tableModel.setColumnCount( tableModel.getColumnCount() - 1 );
|
||||
});
|
||||
JPopupMenu popupMenu = new JPopupMenu();
|
||||
popupMenu.add( addMenuItem );
|
||||
popupMenu.add( removeMenuItem );
|
||||
table1.getTableHeader().setComponentPopupMenu( popupMenu );
|
||||
|
||||
// table column editors
|
||||
initTableEditors( table1 );
|
||||
initTableEditors( xTable1 );
|
||||
@@ -1174,6 +1188,7 @@ public class FlatComponents2Test
|
||||
{ "item 12", null, "December", null, null, null },
|
||||
};
|
||||
|
||||
private int columnCount = columnNames.length;
|
||||
private int rowCount = rows.length;
|
||||
private final Map<Integer, Object[]> moreRowsMap = new HashMap<>();
|
||||
|
||||
@@ -1181,6 +1196,16 @@ public class FlatComponents2Test
|
||||
setRowCount( rowCount );
|
||||
}
|
||||
|
||||
void setColumnCount( int columnCount ) {
|
||||
if( columnCount > columnNames.length )
|
||||
columnCount = columnNames.length;
|
||||
|
||||
this.columnCount = columnCount;
|
||||
|
||||
// fire event
|
||||
fireTableStructureChanged();
|
||||
}
|
||||
|
||||
void setRowCount( int rowCount ) {
|
||||
int oldRowCount = this.rowCount;
|
||||
this.rowCount = rowCount;
|
||||
@@ -1199,7 +1224,7 @@ public class FlatComponents2Test
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return columnNames.length;
|
||||
return columnCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user