Reputation: 1241
I have a list of names and associated values to create checkboxes like
["SAMABULA","CARPETS INTERNATIONAL","HRM/TRAINING"]
["091","094","003"]
How to create checkboxes with these values add these checkboxes to JScrollPane in Netbeans IDE.
This is a Swing application. I created a window from palette and added jscrollpane to that window. But I don't know how to add list of checkboxes to that scrollpane.
Upvotes: 1
Views: 7583
Reputation: 109815
@ Srikanth Dyapa
there are two areas
you have already JList that's contains JCheckBox(es)
then you just declare
JScrollPane myScrollPane = new JScrollPane(myList);
or you have to put your JCheckBox to JList or JPanel but for JPanel with correct LayoutManager for example GridLaoyut
thenarter add your JList or JPanel to the JScrollPane as is above mentioned
maybe ButtonGroup Component can help you with that
Upvotes: 2
Reputation: 13728
In Netbeans you just drag and drop the Check Boxes where you need them. In an Action Listener you use jCheckBox1.isSelected()
in order to check if the user has checked the box or not.
Upvotes: 0
Reputation: 2403
Not sure how to add them in NetBeans as i use Eclipse, but in code would be something like:
JCheckBox chk = new JCheckBox("[LABEL STRING]");
// add event listeners to chk
myScrollPane.add(chk);
see here for more detail and examples: http://download.oracle.com/javase/tutorial/uiswing/components/scrollpane.html
Upvotes: 0