mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27: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 )
|
if( menuBarFactory != null )
|
||||||
setJMenuBar( menuBarFactory.apply( content ) );
|
setJMenuBar( menuBarFactory.apply( content ) );
|
||||||
|
|
||||||
contentPanel.add( content );
|
addContentToContentPanel();
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
setLocationRelativeTo( null );
|
setLocationRelativeTo( null );
|
||||||
setVisible( true );
|
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 ) {
|
private void selectLookAndFeel( String lafClassName ) {
|
||||||
lookAndFeelComboBox.setSelectedLookAndFeel( lafClassName );
|
lookAndFeelComboBox.setSelectedLookAndFeel( lafClassName );
|
||||||
}
|
}
|
||||||
@@ -697,9 +719,9 @@ public class FlatTestFrame
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void recreateContent() {
|
private void recreateContent() {
|
||||||
contentPanel.remove( content );
|
contentPanel.removeAll();
|
||||||
content = contentFactory.get();
|
content = contentFactory.get();
|
||||||
contentPanel.add( content );
|
addContentToContentPanel();
|
||||||
|
|
||||||
if( rightToLeftCheckBox.isSelected() )
|
if( rightToLeftCheckBox.isSelected() )
|
||||||
rightToLeftChanged();
|
rightToLeftChanged();
|
||||||
|
|||||||
Reference in New Issue
Block a user