Skip to content

Commit

Permalink
Allow PluginPanels to opt-out of the scrollbar
Browse files Browse the repository at this point in the history
For panels with tabs it is best to have the scrollbar inside of the tab pane, not around it.
  • Loading branch information
abextm authored and Adam- committed Apr 26, 2018
1 parent 4b92961 commit 4f083f9
Showing 1 changed file with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,44 +36,59 @@

public abstract class PluginPanel extends JPanel
{
static final int PANEL_WIDTH = 225;
public static final int PANEL_WIDTH = 225;
static final int SCROLLBAR_WIDTH = 17;
private static final int OFFSET = 6;
private static final EmptyBorder BORDER_PADDING = new EmptyBorder(OFFSET, OFFSET, OFFSET, OFFSET);
private static final Dimension OUTER_PREFERRED_SIZE = new Dimension(PluginPanel.PANEL_WIDTH + SCROLLBAR_WIDTH, 0);

@Getter(AccessLevel.PROTECTED)
private final JScrollPane scrollPane;

@Getter(AccessLevel.PACKAGE)
private final JPanel wrappedPanel;

public PluginPanel()
protected PluginPanel()
{
this(true);
}

protected PluginPanel(boolean wrap)
{
super();
setBorder(BORDER_PADDING);
setLayout(new GridLayout(0, 1, 0, 3));
if (wrap)
{
setBorder(BORDER_PADDING);
setLayout(new GridLayout(0, 1, 0, 3));

final JPanel northPanel = new JPanel();
northPanel.setLayout(new BorderLayout());
northPanel.add(this, BorderLayout.NORTH);
final JPanel northPanel = new JPanel();
northPanel.setLayout(new BorderLayout());
northPanel.add(this, BorderLayout.NORTH);

scrollPane = new JScrollPane(northPanel);
scrollPane.getVerticalScrollBar().setUnitIncrement(16); //Otherwise scrollspeed is really slow
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane = new JScrollPane(northPanel);
scrollPane.getVerticalScrollBar().setUnitIncrement(16); //Otherwise scrollspeed is really slow
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

wrappedPanel = new JPanel();
wrappedPanel = new JPanel();

// Adjust the preferred size to expand to width of scrollbar to
// to preven scrollbar overlapping over contents
wrappedPanel.setPreferredSize(new Dimension(PluginPanel.PANEL_WIDTH + SCROLLBAR_WIDTH, 0));
wrappedPanel.setLayout(new BorderLayout());
wrappedPanel.add(scrollPane, BorderLayout.CENTER);
// Adjust the preferred size to expand to width of scrollbar to
// to preven scrollbar overlapping over contents
wrappedPanel.setPreferredSize(OUTER_PREFERRED_SIZE);
wrappedPanel.setLayout(new BorderLayout());
wrappedPanel.add(scrollPane, BorderLayout.CENTER);
}
else
{
scrollPane = null;
wrappedPanel = this;
}
}

@Override
public Dimension getPreferredSize()
{
return new Dimension(PANEL_WIDTH, super.getPreferredSize().height);
int width = this == wrappedPanel ? PANEL_WIDTH + SCROLLBAR_WIDTH : PANEL_WIDTH;
return new Dimension(width, super.getPreferredSize().height);
}

public void onActivate()
Expand Down

0 comments on commit 4f083f9

Please sign in to comment.