mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-08 06:50:56 +03:00
Window decorations: do not overwrite maximized bounds if controlled from the application
This commit is contained in:
@@ -43,6 +43,7 @@ import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.BoxLayout;
|
||||
@@ -367,7 +368,11 @@ class FlatTitlePane
|
||||
Frame frame = (Frame) window;
|
||||
|
||||
// set maximized bounds to avoid that maximized window overlaps Windows task bar
|
||||
if( !hasJBRCustomDecoration() ) {
|
||||
// (if not running in JBR and if not modified from the application)
|
||||
if( !hasJBRCustomDecoration() &&
|
||||
(frame.getMaximizedBounds() == null ||
|
||||
Objects.equals( frame.getMaximizedBounds(), rootPane.getClientProperty( "flatlaf.maximizedBounds" ) )) )
|
||||
{
|
||||
GraphicsConfiguration gc = window.getGraphicsConfiguration();
|
||||
|
||||
// Screen bounds, which may be smaller than physical size on Java 9+.
|
||||
@@ -415,6 +420,10 @@ class FlatTitlePane
|
||||
|
||||
// change maximized bounds
|
||||
frame.setMaximizedBounds( maximizedBounds );
|
||||
|
||||
// remember maximized bounds in client property to be able to detect
|
||||
// whether maximized bounds are modified from the application
|
||||
rootPane.putClientProperty( "flatlaf.maximizedBounds", maximizedBounds );
|
||||
}
|
||||
|
||||
// maximize window
|
||||
|
||||
@@ -73,6 +73,8 @@ public class FlatWindowDecorationsTest
|
||||
|
||||
Window window = SwingUtilities.windowForComponent( this );
|
||||
menuBarCheckBox.setEnabled( window instanceof JFrame );
|
||||
menuBarEmbeddedCheckBox.setEnabled( window instanceof JFrame );
|
||||
maximizedBoundsCheckBox.setEnabled( window instanceof Frame );
|
||||
|
||||
boolean windowHasIcons = (window != null && !window.getIconImages().isEmpty());
|
||||
iconNoneRadioButton.setEnabled( windowHasIcons );
|
||||
@@ -118,6 +120,15 @@ public class FlatWindowDecorationsTest
|
||||
((Dialog)window).setResizable( resizableCheckBox.isSelected() );
|
||||
}
|
||||
|
||||
private void maximizedBoundsChanged() {
|
||||
Window window = SwingUtilities.windowForComponent( this );
|
||||
if( window instanceof Frame ) {
|
||||
((Frame)window).setMaximizedBounds( maximizedBoundsCheckBox.isSelected()
|
||||
? new Rectangle( 50, 100, 1000, 700 )
|
||||
: null );
|
||||
}
|
||||
}
|
||||
|
||||
private void menuItemActionPerformed(ActionEvent e) {
|
||||
SwingUtilities.invokeLater( () -> {
|
||||
JOptionPane.showMessageDialog( this, e.getActionCommand(), "Menu Item", JOptionPane.PLAIN_MESSAGE );
|
||||
@@ -189,6 +200,7 @@ public class FlatWindowDecorationsTest
|
||||
menuBarCheckBox = new JCheckBox();
|
||||
menuBarEmbeddedCheckBox = new JCheckBox();
|
||||
resizableCheckBox = new JCheckBox();
|
||||
maximizedBoundsCheckBox = new JCheckBox();
|
||||
JLabel label1 = new JLabel();
|
||||
JLabel label2 = new JLabel();
|
||||
JPanel panel1 = new JPanel();
|
||||
@@ -265,6 +277,11 @@ public class FlatWindowDecorationsTest
|
||||
resizableCheckBox.addActionListener(e -> resizableChanged());
|
||||
add(resizableCheckBox, "cell 0 2");
|
||||
|
||||
//---- maximizedBoundsCheckBox ----
|
||||
maximizedBoundsCheckBox.setText("maximized bounds (50,100, 1000,700)");
|
||||
maximizedBoundsCheckBox.addActionListener(e -> maximizedBoundsChanged());
|
||||
add(maximizedBoundsCheckBox, "cell 1 2");
|
||||
|
||||
//---- label1 ----
|
||||
label1.setText("Style:");
|
||||
add(label1, "cell 0 3");
|
||||
@@ -564,6 +581,7 @@ public class FlatWindowDecorationsTest
|
||||
private JCheckBox menuBarCheckBox;
|
||||
private JCheckBox menuBarEmbeddedCheckBox;
|
||||
private JCheckBox resizableCheckBox;
|
||||
private JCheckBox maximizedBoundsCheckBox;
|
||||
private JRadioButton styleNoneRadioButton;
|
||||
private JRadioButton styleFrameRadioButton;
|
||||
private JRadioButton stylePlainRadioButton;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
JFDML JFormDesigner: "7.0.1.0.272" Java: "13.0.2" encoding: "UTF-8"
|
||||
JFDML JFormDesigner: "7.0.2.0.298" Java: "13.0.2" encoding: "UTF-8"
|
||||
|
||||
new FormModel {
|
||||
contentType: "form/swing"
|
||||
@@ -45,6 +45,16 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 2"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "maximizedBoundsCheckBox"
|
||||
"text": "maximized bounds (50,100, 1000,700)"
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "maximizedBoundsChanged", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 2"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "label1"
|
||||
"text": "Style:"
|
||||
|
||||
Reference in New Issue
Block a user