I have a JList that I need to Place inside a scroll Pane because I am getting the JList from the database and the values can increase greatly. I need to be able to scroll th
As mentioned, the list is already added to JScrollPane
, hence need not be added again. Also, for scroll to work, it needs to define the list method setVisibleRowCount(int)
. I have modified the code above in CheckBoxListener
method to make it work.
Checkboxlistener()
{
setSize(1300, 600);
String labels[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
checkBoxesJList = new JList(labels);
checkBoxesJList.setBounds(10, 30, 80, 600);
checkBoxesJList.setBackground(Color.LIGHT_GRAY);
checkBoxesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
checkBoxesJList.setVisibleRowCount(5);
JScrollPane scrollPane = new JScrollPane(checkBoxesJList);
jpAcc.add(scrollPane);
add(jpAcc);
setVisible(true);
}