I have a panel layout issue that I can't seem to solve. I have the following code:
public class Test extends ApplicationFrame {
public Test(String title) {
super(title);
JPanel jpanel = new JPanel();
jpanel.setPreferredSize(new Dimension(100 * 2, 300));
jpanel.setBackground(new Color(0xFF0000));
JScrollPane scrollPane = new JScrollPane(jpanel);
scrollPane.setBackground(new Color(0xFF0000));
scrollPane.getViewport().setPreferredSize(new Dimension(100 * 2, 300));
this.add(scrollPane, BorderLayout.WEST);
this.setPreferredSize(new Dimension(500, 500));
}
public static void main(String args[]) {
Test test = new Test("Layout Test");
test.pack();
RefineryUtilities.centerFrameOnScreen(test);
test.setVisible(true);
}
}
to create the following layout:
When I drag the right hand side of the window and move it over into the red JPanel
and JScrollPane
, I'd like the horizontal scroll bars to appear on the JScrollPane
. But currently the window just shrinks without showing the horizontal scroll bar. Is this possible?
I'd like to keep the BorderLayout.WEST
since my use case for this is to keep a JFreeChart from stretching when I don't have a big enough chart to fill the entire window.