mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
macOS: setting window background (of undecorated window) to translucent color (alpha < 255) did not show the window translucent (issue #705)
This commit is contained in:
@@ -32,8 +32,10 @@ public class FlatTestPanel
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
|
||||
g.setColor( super.getBackground() );
|
||||
g.fillRect( 0, 0, width, height );
|
||||
if( isOpaque() ) {
|
||||
g.setColor( super.getBackground() );
|
||||
g.fillRect( 0, 0, width, height );
|
||||
}
|
||||
|
||||
if( isPaintBackgroundPattern() ) {
|
||||
g.setColor( Color.magenta );
|
||||
|
||||
@@ -76,6 +76,14 @@ public class FlatWindowDecorationsTest
|
||||
initComponents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUI() {
|
||||
super.updateUI();
|
||||
|
||||
if( translucentWindowBackgroundCheckBox != null )
|
||||
translucentWindowBackgroundChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNotify() {
|
||||
super.addNotify();
|
||||
@@ -237,6 +245,27 @@ public class FlatWindowDecorationsTest
|
||||
}
|
||||
}
|
||||
|
||||
private void translucentWindowBackgroundChanged() {
|
||||
boolean selected = translucentWindowBackgroundCheckBox.isSelected();
|
||||
if( selected && !undecoratedCheckBox.isSelected() ) {
|
||||
undecoratedCheckBox.setSelected( true );
|
||||
undecoratedChanged();
|
||||
}
|
||||
undecoratedCheckBox.setEnabled( !selected );
|
||||
|
||||
Color background = selected
|
||||
? new Color( 100, 0, 0, 100 )
|
||||
: UIManager.getColor( "control" );
|
||||
|
||||
Window window = SwingUtilities.windowForComponent( this );
|
||||
window.setBackground( background );
|
||||
|
||||
for( Component c = this; c != null; c = c.getParent() ) {
|
||||
if( c instanceof JComponent )
|
||||
LookAndFeel.installProperty( (JComponent) c, "opaque", !selected );
|
||||
}
|
||||
}
|
||||
|
||||
private void addMenu() {
|
||||
JMenu menu = new JMenu( "Hello" );
|
||||
menu.add( new JMenuItem( "world" ) );
|
||||
@@ -543,6 +572,7 @@ debug*/
|
||||
colorizeTitleBarCheckBox = new JCheckBox();
|
||||
colorizeMenuBarCheckBox = new JCheckBox();
|
||||
colorizeMenusCheckBox = new JCheckBox();
|
||||
translucentWindowBackgroundCheckBox = new JCheckBox();
|
||||
JButton openDialogButton = new JButton();
|
||||
JButton openFrameButton = new JButton();
|
||||
typeNormalRadioButton = new JRadioButton();
|
||||
@@ -885,6 +915,7 @@ debug*/
|
||||
"[]" +
|
||||
"[]" +
|
||||
"[]" +
|
||||
"[]para" +
|
||||
"[]"));
|
||||
|
||||
//---- unifiedBackgroundCheckBox ----
|
||||
@@ -906,6 +937,11 @@ debug*/
|
||||
colorizeMenusCheckBox.setText("colorize menus");
|
||||
colorizeMenusCheckBox.addActionListener(e -> colorizeMenus());
|
||||
panel5.add(colorizeMenusCheckBox, "cell 0 3");
|
||||
|
||||
//---- translucentWindowBackgroundCheckBox ----
|
||||
translucentWindowBackgroundCheckBox.setText("translucent window background");
|
||||
translucentWindowBackgroundCheckBox.addActionListener(e -> translucentWindowBackgroundChanged());
|
||||
panel5.add(translucentWindowBackgroundCheckBox, "cell 0 4");
|
||||
}
|
||||
add(panel5, "cell 2 1");
|
||||
|
||||
@@ -1169,6 +1205,7 @@ debug*/
|
||||
private JCheckBox colorizeTitleBarCheckBox;
|
||||
private JCheckBox colorizeMenuBarCheckBox;
|
||||
private JCheckBox colorizeMenusCheckBox;
|
||||
private JCheckBox translucentWindowBackgroundCheckBox;
|
||||
private JRadioButton typeNormalRadioButton;
|
||||
private JRadioButton typeUtilityRadioButton;
|
||||
private JRadioButton typeSmallRadioButton;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
JFDML JFormDesigner: "8.1.0.0.283" Java: "19.0.2" encoding: "UTF-8"
|
||||
JFDML JFormDesigner: "8.2.1.0.348" Java: "21.0.1" encoding: "UTF-8"
|
||||
|
||||
new FormModel {
|
||||
contentType: "form/swing"
|
||||
@@ -449,7 +449,7 @@ new FormModel {
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||
"$layoutConstraints": "ltr,hidemode 3,gap 0 0"
|
||||
"$columnConstraints": "[left]"
|
||||
"$rowConstraints": "[][][][]"
|
||||
"$rowConstraints": "[][][][]para[]"
|
||||
} ) {
|
||||
name: "panel5"
|
||||
"border": new javax.swing.border.TitledBorder( "Color" )
|
||||
@@ -493,6 +493,16 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 3"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "translucentWindowBackgroundCheckBox"
|
||||
"text": "translucent window background"
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "translucentWindowBackgroundChanged", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 4"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 1"
|
||||
} )
|
||||
|
||||
Reference in New Issue
Block a user