1

I have a JPanel with a GridLayout(1,0) set to a JFrame Borderlayout.SOUTH, there are placed a couple of buttons in here (when pressed they change a variables value to the index of the created button).

Everything is added correctly, but when I try to update the JPanel it does work at first (only when window is maximized). But then when I go over a button (or all the buttons) it goes back to what the original content of the panel.

I've tried invalidate, validate, repaint, jframe.setvisible(true) - none of these seem to work properly.

Any ideas?

 private void toonHand(){
        JPanel pnlSouth = new JPanel(new GridLayout(1,0));
        JButton[] btnArr =new JButton[50];
        ArrayList<Kaart> Thand=uno.getSpeler(0).getHand();
        for(int i=0;i<Thand.size();i++){
            final int T=i;
            btnArr[i]=new JButton();
            btnArr[i].setIcon(Thand.get(i).getImg());
            btnArr[i].addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    iKaart=T;
                }
            });
            pnlSouth.add(btnArr[i]);
        }
        Hoofdvenster.remove(pnlSouth);
        Hoofdvenster.add(pnlSouth, BorderLayout.SOUTH);
    }
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Petr Safar
  • 107
  • 2
  • 11
  • 1
    *"I've tried.."* Try posting an [SSCCE](http://sscce.org/). – Andrew Thompson Mar 14 '12 at 03:48
  • BTW - *"jframe.setvisible(true) - none of these seem to work properly."* The last one is not spelled (or at least capitalized) correctly. Please take more care when typing class, method & attribute names in questions. These are technical forums, and it is already hard enough to solve theses things remotely, without the added difficulty of guessing what members are being referred to. – Andrew Thompson Mar 14 '12 at 03:51
  • kind of hard since i'm working with multiple objects, pictures, and arrays from before mentioned objects... – Petr Safar Mar 14 '12 at 03:52
  • If it could help you understand; this is some code for making the card game uno. all This should do is create a number of buttons (the same amount as you have cards in your hand) and when you press the button a private variable is changed to the value equal to the index of the button. – Petr Safar Mar 14 '12 at 03:55
  • 1
    *"with multiple objects,"* Declare extra classes as 'default' access in the same source as the public class. (1) *"pictures,"* Hot-link, grab them from the JRE, or generate them in code. (1) *"and arrays"* Are you really saying this problem cannot be reproduced with 1 (or 0) arrays? Even if so, 2-3 short arrays can be included in one SSCCE. 1) ***As mentioned in the SSCCE document which you have apparently either not read, or not understood.*** – Andrew Thompson Mar 14 '12 at 03:57
  • please learn java naming conventions and stick to them – kleopatra Mar 16 '12 at 10:13
  • well i'm sorry that i'm stil a student and not up to your expectations... – Petr Safar Mar 17 '12 at 12:16

1 Answers1

0

The problem was that i was just removing the panel, changing the content and adding it again. Apparently this was giving some issues with displaying the content. I fixed it by putting the panels as global variables, and splitting up the making and updating of the panels. So in every update i remove the panel, make the panel a new Panel and then i make it again.

Petr Safar
  • 107
  • 2
  • 11