FlatTestFrame: automatically add scroll pane if content is very large (or screen is small)

This commit is contained in:
Karl Tauber
2024-05-29 11:14:52 +02:00
parent cc4f9a9db5
commit a54aeb3838

View File

@@ -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();