After reviewing the existing answers to this issue, I am still in the dark here. I am trying to implement scrollable panels inside a tabbed frame. I am using JScrollPane
and JTabbedPane
. However, scrolling is not working.
This is my code:
public TabbedFrame(List<Panel> panels) {
super(new GridLayout(1, 1));
JTabbedPane tabbedPane = new JTabbedPane();
int layerNum = 0;
for (Panel p: panels){
JScrollPane scrollPane = new JScrollPane(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setViewportView(p);
scrollPane.setPreferredSize(new Dimension(500, 500));
tabbedPane.addTab("Layer " + layerNum, null, scrollPane, "Layer " + layerNum);
layerNum++;
}
//Add the tabbed pane to this panel.
add(tabbedPane);
//The following line enables to use scrolling tabs.
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
}
public class Panel extends JPanel{
private static final long serialVersionUID = 4109034958236244752L;
private Design design;
public Panel(Design design){
this.design = design;
this.setSize(design.getCanvasWidth(), design.getCanvasHeight());
}
public void paint(Graphics G) {
G.setColor(design.getColor());
design.draw(G);
}
public int getWidth() { return design.getCanvasWidth(); }
public int getHeight() { return design.getCanvasHeight(); }
}
I will appreciate any help you can offer.