i am trying to make some list of JCheckBoxes and put it inside of a scrollpane.
I tried to make array of checkboxes and put it in JList and then in JScrollPane but it only prints some info about checkboxes from methods.
I want to achieve something like this:
This is my code so far:
public class MainFrame extends JFrame
{
private JPanel panel = new JPanel();
private JScrollPane scroll;
public MainFrame()
{
add();
setTitle("Dropable checkbox");
setSize(500, 500);
add(panel);
setVisible(true);
}
private void add()
{
String categories[] = { "Household", "Office", "Extended Family",
"Company (US)", "Company (World)", "Team", "Will",
"Birthday Card List", "High School", "Country", "Continent",
"Planet","KITA" };
JPanel p = new JPanel();
BoxLayout layout = new BoxLayout(p, BoxLayout.Y_AXIS);
p.setLayout(layout);
for (String string : categories) {
p.add(new JCheckBox(string));
}
JScrollPane scroll = new JScrollPane(p);
panel.add(scroll);
}
}
This is what my screen looks like now