mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
OptionPane: hide window icon by default; can be shown via UI default OptionPane.showIcon = true (issue #416)
This commit is contained in:
@@ -21,6 +21,7 @@ import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import com.formdev.flatlaf.FlatLaf;
|
||||
import net.miginfocom.swing.*;
|
||||
|
||||
/**
|
||||
@@ -44,6 +45,29 @@ class OptionPanePanel
|
||||
"OK",
|
||||
"Cancel",
|
||||
} );
|
||||
|
||||
if( FlatLaf.supportsNativeWindowDecorations() ) {
|
||||
updateShowTitleBarIcon();
|
||||
|
||||
UIManager.getDefaults().addPropertyChangeListener( e -> {
|
||||
switch( e.getPropertyName() ) {
|
||||
case "TitlePane.showIcon":
|
||||
case "TitlePane.useWindowDecorations":
|
||||
updateShowTitleBarIcon();
|
||||
break;
|
||||
}
|
||||
} );
|
||||
} else
|
||||
showTitleBarIconCheckBox.setEnabled( false );
|
||||
}
|
||||
|
||||
private void updateShowTitleBarIcon() {
|
||||
showTitleBarIconCheckBox.setEnabled( UIManager.getBoolean( "TitlePane.showIcon" ) &&
|
||||
FlatLaf.isUseNativeWindowDecorations() );
|
||||
}
|
||||
|
||||
private void showTitleBarIcon() {
|
||||
UIManager.put( "OptionPane.showIcon", showTitleBarIconCheckBox.isSelected() );
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
@@ -54,6 +78,7 @@ class OptionPanePanel
|
||||
JPanel panel1 = new JPanel();
|
||||
JOptionPane plainOptionPane = new JOptionPane();
|
||||
plainShowDialogLabel = new OptionPanePanel.ShowDialogLinkLabel();
|
||||
showTitleBarIconCheckBox = new JCheckBox();
|
||||
JLabel errorLabel = new JLabel();
|
||||
JPanel panel2 = new JPanel();
|
||||
JOptionPane errorOptionPane = new JOptionPane();
|
||||
@@ -93,7 +118,7 @@ class OptionPanePanel
|
||||
//======== panel9 ========
|
||||
{
|
||||
panel9.setLayout(new MigLayout(
|
||||
"flowy,insets dialog,hidemode 3",
|
||||
"insets dialog,hidemode 3",
|
||||
// columns
|
||||
"[]" +
|
||||
"[]" +
|
||||
@@ -126,7 +151,12 @@ class OptionPanePanel
|
||||
//---- plainShowDialogLabel ----
|
||||
plainShowDialogLabel.setOptionPane(plainOptionPane);
|
||||
plainShowDialogLabel.setTitleLabel(plainLabel);
|
||||
panel9.add(plainShowDialogLabel, "cell 2 0");
|
||||
panel9.add(plainShowDialogLabel, "cell 1 0");
|
||||
|
||||
//---- showTitleBarIconCheckBox ----
|
||||
showTitleBarIconCheckBox.setText("Show window title bar icon");
|
||||
showTitleBarIconCheckBox.addActionListener(e -> showTitleBarIcon());
|
||||
panel9.add(showTitleBarIconCheckBox, "cell 2 0");
|
||||
|
||||
//---- errorLabel ----
|
||||
errorLabel.setText("Error");
|
||||
@@ -148,7 +178,7 @@ class OptionPanePanel
|
||||
//---- errorShowDialogLabel ----
|
||||
errorShowDialogLabel.setTitleLabel(errorLabel);
|
||||
errorShowDialogLabel.setOptionPane(errorOptionPane);
|
||||
panel9.add(errorShowDialogLabel, "cell 2 1");
|
||||
panel9.add(errorShowDialogLabel, "cell 1 1");
|
||||
|
||||
//---- informationLabel ----
|
||||
informationLabel.setText("Information");
|
||||
@@ -170,7 +200,7 @@ class OptionPanePanel
|
||||
//---- informationShowDialogLabel ----
|
||||
informationShowDialogLabel.setOptionPane(informationOptionPane);
|
||||
informationShowDialogLabel.setTitleLabel(informationLabel);
|
||||
panel9.add(informationShowDialogLabel, "cell 2 2");
|
||||
panel9.add(informationShowDialogLabel, "cell 1 2");
|
||||
|
||||
//---- questionLabel ----
|
||||
questionLabel.setText("Question");
|
||||
@@ -214,7 +244,7 @@ class OptionPanePanel
|
||||
//---- warningShowDialogLabel ----
|
||||
warningShowDialogLabel.setOptionPane(warningOptionPane);
|
||||
warningShowDialogLabel.setTitleLabel(warningLabel);
|
||||
panel9.add(warningShowDialogLabel, "cell 2 4");
|
||||
panel9.add(warningShowDialogLabel, "cell 1 4");
|
||||
|
||||
//---- inputLabel ----
|
||||
inputLabel.setText("Input");
|
||||
@@ -236,7 +266,7 @@ class OptionPanePanel
|
||||
//---- inputShowDialogLabel ----
|
||||
inputShowDialogLabel.setOptionPane(inputOptionPane);
|
||||
inputShowDialogLabel.setTitleLabel(inputLabel);
|
||||
panel9.add(inputShowDialogLabel, "cell 2 5");
|
||||
panel9.add(inputShowDialogLabel, "cell 1 5");
|
||||
|
||||
//---- inputIconLabel ----
|
||||
inputIconLabel.setText("Input + icon");
|
||||
@@ -259,7 +289,7 @@ class OptionPanePanel
|
||||
//---- inputIconShowDialogLabel ----
|
||||
inputIconShowDialogLabel.setTitleLabel(inputIconLabel);
|
||||
inputIconShowDialogLabel.setOptionPane(inputIconOptionPane);
|
||||
panel9.add(inputIconShowDialogLabel, "cell 2 6");
|
||||
panel9.add(inputIconShowDialogLabel, "cell 1 6");
|
||||
|
||||
//---- customLabel ----
|
||||
customLabel.setText("Custom");
|
||||
@@ -279,7 +309,7 @@ class OptionPanePanel
|
||||
//---- customShowDialogLabel ----
|
||||
customShowDialogLabel.setOptionPane(customOptionPane);
|
||||
customShowDialogLabel.setTitleLabel(customLabel);
|
||||
panel9.add(customShowDialogLabel, "cell 2 7");
|
||||
panel9.add(customShowDialogLabel, "cell 1 7");
|
||||
}
|
||||
scrollPane1.setViewportView(panel9);
|
||||
}
|
||||
@@ -289,6 +319,7 @@ class OptionPanePanel
|
||||
|
||||
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
|
||||
private OptionPanePanel.ShowDialogLinkLabel plainShowDialogLabel;
|
||||
private JCheckBox showTitleBarIconCheckBox;
|
||||
private OptionPanePanel.ShowDialogLinkLabel errorShowDialogLabel;
|
||||
private OptionPanePanel.ShowDialogLinkLabel informationShowDialogLabel;
|
||||
private JOptionPane customOptionPane;
|
||||
@@ -304,6 +335,7 @@ class OptionPanePanel
|
||||
|
||||
ShowDialogLinkLabel() {
|
||||
setText( "<html><a href=\"#\">Show dialog</a></html>" );
|
||||
setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
|
||||
|
||||
addMouseListener( new MouseAdapter() {
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,7 @@ new FormModel {
|
||||
name: "scrollPane1"
|
||||
"border": new javax.swing.border.EmptyBorder( 0, 0, 0, 0 )
|
||||
add( new FormContainer( "com.formdev.flatlaf.demo.ScrollablePanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||
"$layoutConstraints": "flowy,insets dialog,hidemode 3"
|
||||
"$layoutConstraints": "insets dialog,hidemode 3"
|
||||
"$columnConstraints": "[][][fill]"
|
||||
"$rowConstraints": "[top][top][top][top][top][top][top][top]"
|
||||
} ) {
|
||||
@@ -42,6 +42,16 @@ new FormModel {
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 0"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "showTitleBarIconCheckBox"
|
||||
"text": "Show window title bar icon"
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showTitleBarIcon", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 0"
|
||||
} )
|
||||
@@ -73,7 +83,7 @@ new FormModel {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 1"
|
||||
"value": "cell 1 1"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "informationLabel"
|
||||
@@ -103,7 +113,7 @@ new FormModel {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 2"
|
||||
"value": "cell 1 2"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "questionLabel"
|
||||
@@ -157,7 +167,7 @@ new FormModel {
|
||||
"optionPane": new FormReference( "warningOptionPane" )
|
||||
"titleLabel": new FormReference( "warningLabel" )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 4"
|
||||
"value": "cell 1 4"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "inputLabel"
|
||||
@@ -184,7 +194,7 @@ new FormModel {
|
||||
"optionPane": new FormReference( "inputOptionPane" )
|
||||
"titleLabel": new FormReference( "inputLabel" )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 5"
|
||||
"value": "cell 1 5"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "inputIconLabel"
|
||||
@@ -212,7 +222,7 @@ new FormModel {
|
||||
"titleLabel": new FormReference( "inputIconLabel" )
|
||||
"optionPane": new FormReference( "inputIconOptionPane" )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 6"
|
||||
"value": "cell 1 6"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "customLabel"
|
||||
@@ -240,7 +250,7 @@ new FormModel {
|
||||
"optionPane": new FormReference( "customOptionPane" )
|
||||
"titleLabel": new FormReference( "customLabel" )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 7"
|
||||
"value": "cell 1 7"
|
||||
} )
|
||||
} )
|
||||
}, new FormLayoutConstraints( class java.lang.String ) {
|
||||
@@ -248,7 +258,7 @@ new FormModel {
|
||||
} )
|
||||
}, new FormLayoutConstraints( null ) {
|
||||
"location": new java.awt.Point( 0, 0 )
|
||||
"size": new java.awt.Dimension( 840, 900 )
|
||||
"size": new java.awt.Dimension( 955, 900 )
|
||||
} )
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user