What this code should provide is GridLayout 4 columns wide and the rows will depend on which SubChoicesPanel has been selected. The sequence for each row is a JLabel with the subChoices text displayed, a + JButton, a - JButton & a JLabel with 0 in it. I have these and they look OK. However I have trid to give the plus (+) & minus (-) buttons some functionality. Just to test them I have setText to "Yes" for the plus button being pressed and "No" for the minus button being pressed. When I run it only the last row in the GridLayout actually responds when the plus & minus buttons are pressed. I'm only asking as I have spent hours trying to work out what I have done wrong. Please help, (I'll paste the other 2 classes below in case thier needed. Thanks Dave. class: BarTill
There's some wacky numbering going on inside the loop where you are creating the SubChoicesPanel. Everytime through the loop the "j" counter is being reset to 0 and you are saving everything in the arrays based off of this. New references get created and stored, then added to the panel. The panel accesses the actual object, not just the reference, so your new objects get added to the panel each time through the loop, but the arrays where you are saving the references are constantly being overwritten.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
posted 15 years ago
I don't know why it was that int j=0; was in the loop. I moved it to the block before and it comes as no suprise the all the JButtons have listeners. Thanks Nathen.
Nothing? Or something? Like this tiny ad:
create, convert, edit or print DOC and DOCX in Java