JButton icon update problem


I’m creating a JPanel with some JButtons set to different icons to create a seatmap. There are two kinds of JButtons: Existing Seat, Available Seat. The code is set up to allow an Available to switch icon to Existing if pressed. In that case the previous Existing becomes available switching its own icon.

The problem is that the first time the screen is created all available buttons work correctly, but the first selected Existing seat does not go available upon choosing a new seat. If the first existing seat is pressed before pressing an available things work perfectly.

To give an example, when the screen is first created seat 33C is currently selected as the existing seat and seats 32A and 34C are available. If the first button I press is 32A it switches icons to become Existing but 33C does not go to Available. Now if I press any of the other available seats such as 34C 32A becomes available and the new selected seat (34C) becomes Existing. All this time 33C does not change icons - stays at Existing - so I have two Existing seats showing.

However if I click on 33C at any time it becomes “Live” - starts behaving correctly.

Any suggestions/ advice much appreciated. have enclosed code snipped below:

    Iterator it2 = thisRow.values().iterator();
    while (it2.hasNext()) {
      final Seat s = (Seat) it2.next();
      thisSeat = s.row + s.col;

        final JButton seatButton = new JButton();
        seatButton.setIcon( (Icon) iconTable.get(s.status));

        if (thisSeat.equalsIgnoreCase(currSeatStr)) {
          seatButton.setIcon( (Icon) iconTable.get(s.STATUS_EXISTING));
          s.status = s.STATUS_EXISTING;
          innerClassHelperInstance.prevSeatButton = seatButton;
          innerClassHelperInstance.prevSeat = s;

          seatButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              if (s.status.equalsIgnoreCase(s.STATUS_AVAILABLE)) {
                tmpExistingSeatLabel.setText(s.row + s.col);
                innerClassHelperInstance.prevSeat.status = s.
                innerClassHelperInstance.prevSeatButton.setIcon( (Icon)
                seatButton.setIcon( (Icon) iconTable.get(s.STATUS_EXISTING));
                innerClassHelperInstance.prevSeatButton = seatButton;
                innerClassHelperInstance.prevSeat = s;

I have no idea what