I want to add 52 buttons in a JPanel. All with ActionListeners. When I reach a certain amount (13) and run the program, not all of the buttons show up. For example I've added 15 buttons and only 9 or 12 of them show up. Sometimes all of them, but not every time.
Here's the code for two of the JButtons:
JButton button_one=new JButton();
button_one.setPreferredSize(new Dimension(100,150));
mainpanel.add(button_one);
button_one.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent button_1_picked){
amount_of_cards_picked=amount_of_cards_picked+1;
cardamountcheck();
if(twocardspicked==true){
userpick2=0;
System.out.println(setoutcards[userpick2]);
pairdetermination();
}
else if(twocardspicked==false){
userpick1=0;
System.out.println(setoutcards[userpick1]);
}
}
});
JButton button_two = new JButton();
button_two.setPreferredSize(new Dimension(100, 150));
mainpanel.add(button_two);
button_two.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent button_2_picked){
amount_of_cards_picked=amount_of_cards_picked+1;
cardamountcheck();
if(twocardspicked==true){
userpick2=1;
System.out.println(setoutcards[userpick2]);
pairdetermination();
}
else if(twocardspicked==false){
userpick1=1;
System.out.println(setoutcards[userpick1]);
}
}
});
Basically when one of these buttons are clicked, variables in my code get changed. These buttons run fine and work exactly how I want them to, but they don't all appear when there is more than 13 of them, and I need 52.