Allow PluginPanels to opt-out of the scrollbar
For panels with tabs it is best to have the scrollbar inside of the tab pane, not around it.
This commit is contained in:
@@ -36,10 +36,11 @@ import lombok.Getter;
|
|||||||
|
|
||||||
public abstract class PluginPanel extends JPanel
|
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;
|
static final int SCROLLBAR_WIDTH = 17;
|
||||||
private static final int OFFSET = 6;
|
private static final int OFFSET = 6;
|
||||||
private static final EmptyBorder BORDER_PADDING = new EmptyBorder(OFFSET, OFFSET, OFFSET, OFFSET);
|
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)
|
@Getter(AccessLevel.PROTECTED)
|
||||||
private final JScrollPane scrollPane;
|
private final JScrollPane scrollPane;
|
||||||
@@ -47,33 +48,47 @@ public abstract class PluginPanel extends JPanel
|
|||||||
@Getter(AccessLevel.PACKAGE)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private final JPanel wrappedPanel;
|
private final JPanel wrappedPanel;
|
||||||
|
|
||||||
public PluginPanel()
|
protected PluginPanel()
|
||||||
|
{
|
||||||
|
this(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PluginPanel(boolean wrap)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
setBorder(BORDER_PADDING);
|
if (wrap)
|
||||||
setLayout(new GridLayout(0, 1, 0, 3));
|
{
|
||||||
|
setBorder(BORDER_PADDING);
|
||||||
|
setLayout(new GridLayout(0, 1, 0, 3));
|
||||||
|
|
||||||
final JPanel northPanel = new JPanel();
|
final JPanel northPanel = new JPanel();
|
||||||
northPanel.setLayout(new BorderLayout());
|
northPanel.setLayout(new BorderLayout());
|
||||||
northPanel.add(this, BorderLayout.NORTH);
|
northPanel.add(this, BorderLayout.NORTH);
|
||||||
|
|
||||||
scrollPane = new JScrollPane(northPanel);
|
scrollPane = new JScrollPane(northPanel);
|
||||||
scrollPane.getVerticalScrollBar().setUnitIncrement(16); //Otherwise scrollspeed is really slow
|
scrollPane.getVerticalScrollBar().setUnitIncrement(16); //Otherwise scrollspeed is really slow
|
||||||
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
|
|
||||||
wrappedPanel = new JPanel();
|
wrappedPanel = new JPanel();
|
||||||
|
|
||||||
// Adjust the preferred size to expand to width of scrollbar to
|
// Adjust the preferred size to expand to width of scrollbar to
|
||||||
// to preven scrollbar overlapping over contents
|
// to preven scrollbar overlapping over contents
|
||||||
wrappedPanel.setPreferredSize(new Dimension(PluginPanel.PANEL_WIDTH + SCROLLBAR_WIDTH, 0));
|
wrappedPanel.setPreferredSize(OUTER_PREFERRED_SIZE);
|
||||||
wrappedPanel.setLayout(new BorderLayout());
|
wrappedPanel.setLayout(new BorderLayout());
|
||||||
wrappedPanel.add(scrollPane, BorderLayout.CENTER);
|
wrappedPanel.add(scrollPane, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scrollPane = null;
|
||||||
|
wrappedPanel = this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize()
|
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()
|
public void onActivate()
|
||||||
|
|||||||
Reference in New Issue
Block a user