mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-10 22:17:13 -06:00
FlatTestFrame: automatically add scroll pane if content is very large (or screen is small)
This commit is contained in:
@@ -340,7 +340,8 @@ public class FlatTestFrame
|
||||
if( menuBarFactory != null )
|
||||
setJMenuBar( menuBarFactory.apply( content ) );
|
||||
|
||||
contentPanel.add( content );
|
||||
addContentToContentPanel();
|
||||
|
||||
pack();
|
||||
setLocationRelativeTo( null );
|
||||
setVisible( true );
|
||||
@@ -350,6 +351,27 @@ public class FlatTestFrame
|
||||
} );
|
||||
}
|
||||
|
||||
private void addContentToContentPanel() {
|
||||
if( content instanceof JScrollPane ) {
|
||||
contentPanel.add( content );
|
||||
return;
|
||||
}
|
||||
|
||||
Dimension contentSize = content.getPreferredSize();
|
||||
int buttonBarHeight = buttonBar.getPreferredSize().height;
|
||||
Rectangle screenBounds = getGraphicsConfiguration().getBounds();
|
||||
|
||||
// add scroll pane if content is larger than screen
|
||||
if( contentSize.width > screenBounds.width ||
|
||||
contentSize.height + buttonBarHeight > screenBounds.height )
|
||||
{
|
||||
JScrollPane scrollPane = new JScrollPane( content );
|
||||
scrollPane.setBorder( BorderFactory.createEmptyBorder() );
|
||||
contentPanel.add( scrollPane );
|
||||
} else
|
||||
contentPanel.add( content );
|
||||
}
|
||||
|
||||
private void selectLookAndFeel( String lafClassName ) {
|
||||
lookAndFeelComboBox.setSelectedLookAndFeel( lafClassName );
|
||||
}
|
||||
@@ -697,9 +719,9 @@ public class FlatTestFrame
|
||||
}
|
||||
|
||||
private void recreateContent() {
|
||||
contentPanel.remove( content );
|
||||
contentPanel.removeAll();
|
||||
content = contentFactory.get();
|
||||
contentPanel.add( content );
|
||||
addContentToContentPanel();
|
||||
|
||||
if( rightToLeftCheckBox.isSelected() )
|
||||
rightToLeftChanged();
|
||||
|
||||
Reference in New Issue
Block a user