mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-08 06:50:56 +03:00
List: use inactive selection background/foreground if list is not focused
This commit is contained in:
@@ -16,7 +16,15 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.ListCellRenderer;
|
||||||
|
import javax.swing.ListModel;
|
||||||
|
import javax.swing.ListSelectionModel;
|
||||||
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicListUI;
|
import javax.swing.plaf.basic.BasicListUI;
|
||||||
|
|
||||||
@@ -25,12 +33,64 @@ import javax.swing.plaf.basic.BasicListUI;
|
|||||||
*
|
*
|
||||||
* TODO document used UI defaults of superclass
|
* TODO document used UI defaults of superclass
|
||||||
*
|
*
|
||||||
|
* @uiDefault List.selectionInactiveBackground Color
|
||||||
|
* @uiDefault List.selectionInactiveForeground Color
|
||||||
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
public class FlatListUI
|
public class FlatListUI
|
||||||
extends BasicListUI
|
extends BasicListUI
|
||||||
{
|
{
|
||||||
|
protected Color selectionInactiveBackground;
|
||||||
|
protected Color selectionInactiveForeground;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatListUI();
|
return new FlatListUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void installDefaults() {
|
||||||
|
super.installDefaults();
|
||||||
|
|
||||||
|
selectionInactiveBackground = UIManager.getColor( "List.selectionInactiveBackground" );
|
||||||
|
selectionInactiveForeground = UIManager.getColor( "List.selectionInactiveForeground" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void uninstallDefaults() {
|
||||||
|
super.uninstallDefaults();
|
||||||
|
|
||||||
|
selectionInactiveBackground = null;
|
||||||
|
selectionInactiveForeground = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as super.paintCell(), but uses inactive selection background/foreground if list is not focused.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings( { "rawtypes", "unchecked" } )
|
||||||
|
protected void paintCell( Graphics g, int row, Rectangle rowBounds, ListCellRenderer cellRenderer,
|
||||||
|
ListModel dataModel, ListSelectionModel selModel, int leadIndex )
|
||||||
|
{
|
||||||
|
Object value = dataModel.getElementAt( row );
|
||||||
|
boolean hasFocus = list.hasFocus();
|
||||||
|
boolean cellHasFocus = hasFocus && (row == leadIndex);
|
||||||
|
boolean isSelected = selModel.isSelectedIndex( row );
|
||||||
|
|
||||||
|
// get renderer component
|
||||||
|
Component rendererComponent = cellRenderer.getListCellRendererComponent(
|
||||||
|
list, value, row, isSelected, cellHasFocus );
|
||||||
|
|
||||||
|
// apply inactive selection background/foreground if list is not focused
|
||||||
|
if( isSelected && !hasFocus ) {
|
||||||
|
if( rendererComponent.getBackground() == list.getSelectionBackground() )
|
||||||
|
rendererComponent.setBackground( selectionInactiveBackground );
|
||||||
|
if( rendererComponent.getForeground() == list.getSelectionForeground() )
|
||||||
|
rendererComponent.setForeground( selectionInactiveForeground );
|
||||||
|
}
|
||||||
|
|
||||||
|
// paint renderer
|
||||||
|
rendererPane.paintComponent( g, rendererComponent, list,
|
||||||
|
rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height, true );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
@foreground=bbbbbb
|
@foreground=bbbbbb
|
||||||
@selectionBackground=4B6EAF
|
@selectionBackground=4B6EAF
|
||||||
@selectionForeground=@foreground
|
@selectionForeground=@foreground
|
||||||
|
@selectionInactiveBackground=0D293E
|
||||||
|
@selectionInactiveForeground=@foreground
|
||||||
@disabledText=777777
|
@disabledText=777777
|
||||||
@textComponentBackground=45494A
|
@textComponentBackground=45494A
|
||||||
@cellFocusColor=000000
|
@cellFocusColor=000000
|
||||||
|
|||||||
@@ -165,6 +165,8 @@ List.border=1,0,1,0
|
|||||||
List.cellNoFocusBorder=1,6,1,6
|
List.cellNoFocusBorder=1,6,1,6
|
||||||
List.focusCellHighlightBorder=1,6,1,6,@cellFocusColor
|
List.focusCellHighlightBorder=1,6,1,6,@cellFocusColor
|
||||||
List.focusSelectedCellHighlightBorder=1,6,1,6,@cellFocusColor
|
List.focusSelectedCellHighlightBorder=1,6,1,6,@cellFocusColor
|
||||||
|
List.selectionInactiveBackground=@selectionInactiveBackground
|
||||||
|
List.selectionInactiveForeground=@selectionInactiveForeground
|
||||||
|
|
||||||
|
|
||||||
#---- Menu ----
|
#---- Menu ----
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
@foreground=000000
|
@foreground=000000
|
||||||
@selectionBackground=4A6EB7
|
@selectionBackground=4A6EB7
|
||||||
@selectionForeground=ffffff
|
@selectionForeground=ffffff
|
||||||
|
@selectionInactiveBackground=d4d4d4
|
||||||
|
@selectionInactiveForeground=@foreground
|
||||||
@disabledText=999999
|
@disabledText=999999
|
||||||
@textComponentBackground=ffffff
|
@textComponentBackground=ffffff
|
||||||
@cellFocusColor=000000
|
@cellFocusColor=000000
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
@background=ccffcc
|
@background=ccffcc
|
||||||
@selectionBackground=00aa00
|
@selectionBackground=00aa00
|
||||||
|
@selectionInactiveBackground=888888
|
||||||
|
@selectionInactiveForeground=ffffff
|
||||||
@textComponentBackground=ffffff
|
@textComponentBackground=ffffff
|
||||||
@cellFocusColor=ff0000
|
@cellFocusColor=ff0000
|
||||||
@icon=afafaf
|
@icon=afafaf
|
||||||
|
|||||||
Reference in New Issue
Block a user