I try to make a scrollbar for a JPanel but when I RUN, the scrollbar not even show up.
EDITED: This is the latest code, I updated the contentPane layout.
This is main Panel:
contentPane = new JPanel();
contentPane.setBackground(Color.WHITE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setPreferredSize(new Dimension(1200, 400));
setContentPane(contentPane);
This is JPanel inside the main Panel:
bigPanel = new JPanel();
bigPanel.setPreferredSize(new Dimension(1137, 520));
bigPanel.setBackground(new Color(224, 255, 255));
JScrollPane scrollPane = new JScrollPane(bigPanel);
scrollPane.setPreferredSize(new Dimension(600, 600));
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
contentPane.add(scrollPane,"1, 2, 6, 1, center, default");
bigPanel.setLayout(new FormLayout(new ColumnSpec[] {...}
bigPanel.add(BUTTON1);
bigPanel.add(BUTTON2);.....
Above code was written under:
public UI2(){...}
This is the launch application code:
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UI2 frame = new UI2();
frame.pack();
frame.setDefaultCloseOperation(UI2.EXIT_ON_CLOSE);
frame.setSize(1376,788);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
bigPanel has many buttons. So I need a vertical and horizontal scrollbar within bigPanel.
This is the screenshot after I RUN but no scrollbar shown:
EDITED: This is the latest screenshot, the bigPanel shows empty after I wrote the code as above.