Skip to content

Commit

Permalink
FlatTestFrame: automatically add scroll pane if content is very large…
Browse files Browse the repository at this point in the history
… (or screen is small)
  • Loading branch information
DevCharly committed May 29, 2024
1 parent cc4f9a9 commit a54aeb3
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ public void showFrame( Supplier<JComponent> contentFactory, Function<JComponent,
if( menuBarFactory != null )
setJMenuBar( menuBarFactory.apply( content ) );

contentPanel.add( content );
addContentToContentPanel();

pack();
setLocationRelativeTo( null );
setVisible( true );
Expand All @@ -350,6 +351,27 @@ public void showFrame( Supplier<JComponent> contentFactory, Function<JComponent,
} );
}

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 );
}
Expand Down Expand Up @@ -697,9 +719,9 @@ private void opaqueChanged() {
}

private void recreateContent() {
contentPanel.remove( content );
contentPanel.removeAll();
content = contentFactory.get();
contentPanel.add( content );
addContentToContentPanel();

if( rightToLeftCheckBox.isSelected() )
rightToLeftChanged();
Expand Down

0 comments on commit a54aeb3

Please sign in to comment.