• Post Reply Bookmark Topic Watch Topic
  • New Topic

Some buttons do... Some buttons don't...

 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my class: SubChoicesPanel

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

 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Try running this code all by its lonesome. I don't think it does what you think it does.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!