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);
}