Table: fixed cell focus indicator border hiding for boolean columns (issue #654)

This commit is contained in:
Karl Tauber
2023-03-28 13:32:33 +02:00
parent d27a246dfe
commit 2e878b62d1

View File

@@ -24,6 +24,7 @@ import java.util.function.Function;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.plaf.TableUI; import javax.swing.plaf.TableUI;
/** /**
@@ -107,6 +108,28 @@ public class FlatTableCellBorder
public static class Focused public static class Focused
extends FlatTableCellBorder 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 ----------------------------------------------------- //---- class Selected -----------------------------------------------------