Made JComboBox, JProgressBar, JSpinner and JXDatePicker non-opaque.

`JPasswordField`, `JScrollPane` and `JTextField` are non-opaque if they have
an outside focus border (e.g. IntelliJ and Darcula themes).
(issues #20 and #17)
This commit is contained in:
Karl Tauber
2019-10-25 10:20:02 +02:00
parent 8b8d84c2a3
commit bc10c4e871
12 changed files with 194 additions and 106 deletions

View File

@@ -58,6 +58,7 @@ public class FlatInspector
private Component lastComponent;
private int lastX;
private int lastY;
private boolean inspectParent;
private JComponent highlightFigure;
private JToolTip tip;
@@ -70,6 +71,7 @@ public class FlatInspector
public void mouseMoved( MouseEvent e ) {
lastX = e.getX();
lastY = e.getY();
inspectParent = e.isShiftDown();
inspect( lastX, lastY );
}
} );
@@ -105,6 +107,8 @@ public class FlatInspector
private void inspect( int x, int y ) {
Container contentPane = rootPane.getContentPane();
Component c = SwingUtilities.getDeepestComponentAt( contentPane, x, y );
if( inspectParent && c != null && c != contentPane )
c = c.getParent();
if( c == contentPane || (c != null && c.getParent() == contentPane) )
c = null;
@@ -237,7 +241,8 @@ public class FlatInspector
}
text += "Enabled: " + c.isEnabled() + '\n';
text += "Opaque: " + c.isOpaque() + '\n';
text += "Opaque: " + c.isOpaque() + (c instanceof JComponent &&
FlatUIUtils.hasOpaqueBeenExplicitlySet( (JComponent) c ) ? " EXPLICIT" : "") + '\n';
text += "Focusable: " + c.isFocusable() + '\n';
text += "Left-to-right: " + c.getComponentOrientation().isLeftToRight() + '\n';
text += "Parent: " + c.getParent().getClass().getName();

View File

@@ -307,7 +307,7 @@ public class FlatTestFrame
c.setBackground( explicit ? Color.orange : restoreColor );
} else {
c.setForeground( explicit ? Color.blue : restoreColor );
c.setBackground( explicit ? Color.red : restoreColor );
c.setBackground( explicit ? Color.green : restoreColor );
}
} );
@@ -425,6 +425,14 @@ public class FlatTestFrame
contentPanel.getContentPane().remove( content );
content = contentFactory.get();
contentPanel.getContentPane().add( content );
if( rightToLeftCheckBox.isSelected() )
rightToLeftChanged();
if( !enabledCheckBox.isSelected() )
enabledChanged();
if( explicitColorsCheckBox.isSelected() )
explicitColorsChanged();
contentPanel.revalidate();
contentPanel.repaint();
}

View File

@@ -29,15 +29,29 @@ public class FlatTestPanel
{
@Override
protected void paintComponent( Graphics g ) {
super.paintComponent( g );
int width = getWidth();
int height = getHeight();
FlatTestFrame frame = (FlatTestFrame) SwingUtilities.getAncestorOfClass( FlatTestFrame.class, this );
if( frame != null && frame.isPaintBackgroundPattern() ) {
g.setColor( super.getBackground() );
g.fillRect( 0, 0, width, height );
if( isPaintBackgroundPattern() ) {
g.setColor( Color.magenta );
int width = getWidth();
int height = getHeight();
for( int y = 0; y < height; y += 2 )
g.drawLine( 0, y, width - 1, y );
}
}
/**
* Overridden to see which components paint background with color from parent.
*/
@Override
public Color getBackground() {
return isPaintBackgroundPattern() ? Color.red : super.getBackground();
}
private boolean isPaintBackgroundPattern() {
FlatTestFrame frame = (FlatTestFrame) SwingUtilities.getAncestorOfClass( FlatTestFrame.class, this );
return frame != null && frame.isPaintBackgroundPattern();
}
}