From 2e878b62d1cbd5c9d8d5eba476ab6644aaea921d Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 28 Mar 2023 13:32:33 +0200 Subject: [PATCH] Table: fixed cell focus indicator border hiding for boolean columns (issue #654) --- .../flatlaf/ui/FlatTableCellBorder.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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 81e4f37b..018b045d 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 @@ -24,6 +24,7 @@ import java.util.function.Function; import javax.swing.JTable; import javax.swing.SwingUtilities; import javax.swing.UIManager; +import javax.swing.border.Border; import javax.swing.plaf.TableUI; /** @@ -107,6 +108,28 @@ public class FlatTableCellBorder public static class Focused extends FlatTableCellBorder { + @Override + public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) { + if( c != null && c.getClass().getName().equals( "javax.swing.JTable$BooleanRenderer" ) ) { + // boolean renderer in JTable does not use Table.focusSelectedCellHighlightBorder + // if cell is selected and focused (as DefaultTableCellRenderer does) + // --> delegate to Table.focusSelectedCellHighlightBorder + // to make FlatLaf "focus indicator border hiding" work + JTable table = (JTable) SwingUtilities.getAncestorOfClass( JTable.class, c ); + if( table != null && + c.getForeground() == table.getSelectionForeground() && + c.getBackground() == table.getSelectionBackground() ) + { + Border border = UIManager.getBorder( "Table.focusSelectedCellHighlightBorder" ); + if( border != null ) { + border.paintBorder( c, g, x, y, width, height ); + return; + } + } + } + + super.paintBorder( c, g, x, y, width, height ); + } } //---- class Selected -----------------------------------------------------