diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableCellBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableCellBorder.java index 018b045d..b22dc6fc 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableCellBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableCellBorder.java @@ -135,18 +135,21 @@ public class FlatTableCellBorder //---- class Selected ----------------------------------------------------- /** - * Border for selected cell that uses margins and paints focus indicator border + * Border for selected cell that uses margins and paints focus indicator border. + * The focus indicator is shown under following conditions: *
- * To avoid possible performance issues, checking for editable cell is limited - * to {@link #maxCheckCellsEditable}. + * To avoid possible performance issues, checking for editable cells is limited + * to {@link #maxCheckCellsEditable}. If there are more cells to check, + * the focus indicator is always shown. */ public static class Selected extends FlatTableCellBorder @@ -174,48 +177,53 @@ public class FlatTableCellBorder * @since 3.1 */ protected boolean shouldShowCellFocusIndicator( JTable table ) { - // show always for column only selection - // (do not check for editable cells because there may be thousands or millions of rows) - if( !table.getRowSelectionAllowed() ) - return true; + boolean rowSelectionAllowed = table.getRowSelectionAllowed(); + boolean columnSelectionAllowed = table.getColumnSelectionAllowed(); - // do not show if more than one row is selected - // (unlikely that user wants edit cell in this case) - if( table.getSelectedRowCount() != 1 ) + // do not show for cell selection mode + // (unlikely that user wants edit cell in case that multiple cells are selected; + // if only a single cell is selected then it is clear where the focus is) + if( rowSelectionAllowed && columnSelectionAllowed ) return false; - int selectedRow = table.getSelectedRow(); + if( rowSelectionAllowed ) { + // row selection mode - if( table.getColumnSelectionAllowed() ) { - // column and row selection are allowed --> cell selection enabled - int selectedColumnCount = table.getSelectedColumnCount(); - - // do not show if exactly one cell is selected - if( selectedColumnCount == 1 ) + // do not show if more than one row is selected + // (unlikely that user wants edit cell in this case) + if( table.getSelectedRowCount() != 1 ) return false; // show always if there are too many columns to check for editable - if( selectedColumnCount > maxCheckCellsEditable ) - return true; - - // check whether at least one selected cell is editable - for( int selectedColumn : table.getSelectedColumns() ) { - if( table.isCellEditable( selectedRow, selectedColumn ) ) - return true; - } - } else { - // row selection enabled int columnCount = table.getColumnCount(); - - // show always if there are too many columns to check for editable if( columnCount > maxCheckCellsEditable ) return true; // check whether at least one selected cell is editable + int selectedRow = table.getSelectedRow(); for( int column = 0; column < columnCount; column++ ) { if( table.isCellEditable( selectedRow, column ) ) return true; } + } else if( columnSelectionAllowed ) { + // column selection mode + + // do not show if more than one column is selected + // (unlikely that user wants edit cell in this case) + if( table.getSelectedColumnCount() != 1 ) + return false; + + // show always if there are too many rows to check for editable + int rowCount = table.getRowCount(); + if( rowCount > maxCheckCellsEditable ) + return true; + + // check whether at least one selected cell is editable + int selectedColumn = table.getSelectedColumn(); + for( int row = 0; row < rowCount; row++ ) { + if( table.isCellEditable( row, selectedColumn ) ) + return true; + } } return false;