I have an app that admittedly is homework, but it is not a requirement of the assignment. I have a radioButton group of accounts...simple enough, and we have five accounts. Since I like making things harder than they need to be, I decided to create the group dynamically (after all, at some point I might have more than 5 accounts). I also decided it should really be in a scroll panel also, otherwise there will be no room for expansion.
The code to create the button group is pretty trivial:
Basic listener code
I am stuck on the listener part....if I do a getText(), it returns the name of the last button added. I can do a buttonGroup.getSelection() which returns a unique value for each button, but I need to be able to either retrieve the position of the button within the group, or then text of the button to really do anything useful with it.
Anybody have an idea how I can accomplish this? There has to be a way to do it, I just can't see it. [ March 20, 2005: Message edited by: C. Alan ]
<a href="http://www.security-forums.com/forum/viewforum.php?f=48" target="_blank" rel="nofollow">Malware Removal</a> - Get your system running like new again.
Joined: Dec 17, 2004
I apologize for the duplicate post, but I figured out the solution to my own problem, which usuallly happens five minutes after I ask the question (even if I spet 6 hours trying to figure it out)
Anyway, I made some modifications:
Then in the listener:
Now I am able to get the index of the button pushed, and I can use the index to correlate to the proper account...woot!
hello sir, This is not an answer to your question but I have similar kind of a problem to use listener for dynamic jtextpane. if you could have an answer to it, please share it with me. i create jtextpanes in loop based on a condition and add the listener inside the loop. but the problem i have is the actionperformed gets called as many times the length of the jtextpanes created. if i can try a similar one like jradiobutton, how can i identify which jtextpane is focussed to call the listener.
the person you are directing your question to hasn't posted here in 5 years.
you are better off starting your own thread, by posting in the Swing forum,
and better still would be to post a compilable/runnable demo program that
displays the problem i.e. don't include anything in the program that is not related to the problem