I want to make the window scrollable with checkboxes inserted vertically in order.
In the code below, checkboxes are displayed as I want, but the window is not scrollable. Any help would be appreciated.
JFrame frame;
frame = new JFrame();
frame.setBounds(100, 100, 150, 300);
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.getContentPane().setLayout(null);
chckbxNewCheckBox = new JCheckBox[emratStudent.length];
JPanel panel = new JPanel();
panel.setBounds(0, 0, 150, 300);
panel.setLayout(null);
for (int i = 1; i < studentNames.length; i++) {
chckbxNewCheckBox[i] = new JCheckBox();
chckbxNewCheckBox[i].setText(studentNames[i]);
chckbxNewCheckBox[i].setBounds(0, (i-1)*25, 150, 23);
chckbxNewCheckBox[i].setBackground(Color.pink);
panel.add(chckbxNewCheckBox[i]);
}
JScrollPane scrollPane1 = new JScrollPane(panel);
scrollPane1.setBounds(0, 0, 130, 600);
frame.getContentPane().add(scrollPane1);
Aucun commentaire:
Enregistrer un commentaire