File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ItemListener identifying which JCheckBox from array is chosen?

 
wayne morton
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I create a GUI with 10 check boxes but these check boxes are from an array and all have the same name.e.g.



I tick box 4 and i want it to tell me which box i have ticked...how do i get that reference so can get the label to read out "You have ticked box 4"?

I can get it's reference in the sense that it says test, but they all say test, so which test box did you tick?


The obvious solution is to make the for loop give them all a different name.e.g.test1, test2 etc but they all have to have the same name because in the real instance of what i am doing i have a tabbed pane and on clicking "New Tab" it creates a replica of the existing tab so checkbox[1] in in tab 1, checkbox[2] is in tab 2 etc and when i tick a box i need to makes it's actions relevant only to that tab.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using one Listener: nice non‑object‑oriented programming. Create a Listener for each button; you would probably have to write a NumberListener or similar. Add it to the button (one instance each) in the loop. You can use the same String to number the buttons, label them, and to use in the NumberListenerₑs methods.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic