I am trying to create a JFrame with bunch of Jbuttons on it,. 40 in the middle, in rows of 4, and 6 Jbuttons in a vertical line going down the left side. The problem is, the fifth Jbutton down the side buttons appears behind all the others, and takes up the entire window. I ave no idea where this comes from, because I never set JButton's size to be that big, or to fit the screen.
import javax.swing.*;
public class Buttons {
static JButton[][] middle = new JButton [10][4]; //middle buttons
static JButton[] colours = new JButton[6]; //colour buttons
public static void main (String arg[]) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,700);
int xcor = 100; //x coordinate
int ycor = 5; //y coordinate
//middle buttons
for (int y = 0; y<10; y++) {
for (int x = 0; x<4; x++) {
middle[y][x] = new JButton();
middle[y][x].setBounds(xcor, ycor, 100, 60);
middle[y][x].setVisible(true);
frame.getContentPane().add(middle[y][x]);
xcor+=100;
}
xcor=100;
ycor+=60;
}
//colour buttons
ycor=65;
for (int y = 0; y<5; y++){
colours[y] = new JButton();
colours[y].setBounds(5, ycor, 90, 60);
switch (y) {
case 0: colours[y].setText("Red");
break;
case 1: colours[y].setText("Blue");
break;
case 2: colours[y].setText("Green");
break;
case 3: colours[y].setText("Yellow");
break;
case 4: colours[y].setText("Purple");
break;
case 5: colours[y].setText("Black");
break;
}
colours[y].setVisible(true);
frame.getContentPane().add(colours[y]);
ycor += 60;
}
frame.setVisible(true);
}