mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 07:17:13 -06:00
UI defaults inspector: avoid that restored window bounds are outside of screens
This commit is contained in:
@@ -87,6 +87,7 @@ public class FlatUIDefaultsInspector
|
|||||||
|
|
||||||
public static void show() {
|
public static void show() {
|
||||||
if( inspector != null ) {
|
if( inspector != null ) {
|
||||||
|
inspector.ensureOnScreen();
|
||||||
inspector.frame.toFront();
|
inspector.frame.toFront();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -143,9 +144,10 @@ public class FlatUIDefaultsInspector
|
|||||||
int width = prefs.getInt( "width", UIScale.scale( 600 ) );
|
int width = prefs.getInt( "width", UIScale.scale( 600 ) );
|
||||||
int height = prefs.getInt( "height", UIScale.scale( 800 ) );
|
int height = prefs.getInt( "height", UIScale.scale( 800 ) );
|
||||||
frame.setSize( width, height );
|
frame.setSize( width, height );
|
||||||
if( x >= 0 && y >= 0 )
|
if( x != -1 && y != -1 ) {
|
||||||
frame.setLocation( x, y );
|
frame.setLocation( x, y );
|
||||||
else
|
ensureOnScreen();
|
||||||
|
} else
|
||||||
frame.setLocationRelativeTo( null );
|
frame.setLocationRelativeTo( null );
|
||||||
|
|
||||||
// restore column widths
|
// restore column widths
|
||||||
@@ -193,6 +195,23 @@ public class FlatUIDefaultsInspector
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ensureOnScreen() {
|
||||||
|
Rectangle frameBounds = frame.getBounds();
|
||||||
|
boolean onScreen = false;
|
||||||
|
for( GraphicsDevice screen : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices() ) {
|
||||||
|
GraphicsConfiguration gc = screen.getDefaultConfiguration();
|
||||||
|
Rectangle screenBounds = FlatUIUtils.subtractInsets( gc.getBounds(),
|
||||||
|
Toolkit.getDefaultToolkit().getScreenInsets( gc ) );
|
||||||
|
if( frameBounds.intersects( screenBounds ) ) {
|
||||||
|
onScreen = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !onScreen )
|
||||||
|
frame.setLocationRelativeTo( null );
|
||||||
|
}
|
||||||
|
|
||||||
void lafChanged( PropertyChangeEvent e ) {
|
void lafChanged( PropertyChangeEvent e ) {
|
||||||
if( "lookAndFeel".equals( e.getPropertyName() ) )
|
if( "lookAndFeel".equals( e.getPropertyName() ) )
|
||||||
refresh();
|
refresh();
|
||||||
|
|||||||
Reference in New Issue
Block a user