I'm trying to make a simple game where you can set out tiles that make up a celtic design and I can't seem to make the buttons stay the same size. Here's the code:
public class CTGContent {
public static JPanel content = new JPanel();
private static JButton board[][] = new JButton[20][20];
static private Random random = new Random();
public static int CTGcolumn = random.nextInt(14)+1;
public static int CTGRow = 15;
private static GridLayout boardLayout;
public final int getBoardWidth(){
return CTGcolumn*40;
}
public final int getBoardHeight(){
return CTGRow*40;
}
public static void initializeBoard(){
int row = 0;
int column = 0;
int defaultCOL = 0;
int defaultROW = 0;
boardLayout = new GridLayout(CTGRow, CTGcolumn);
content.setLayout(boardLayout);
Random determine = new Random();
while (row < CTGRow){
column = 0;
while (column < CTGcolumn){
board[row][column] = new JButton(new ImageIcon("images\\template.gif"));
board[row][column].setPreferredSize(new Dimension(40, 40));
board[row][column].setMaximumSize(new Dimension(40, 40));
board[row][column].setMinimumSize(new Dimension(40, 40));
content.add(board[row][column]);
column++;
}
row++;
}
}
private static void build(){
initializeBoard();
JFrame window = new JFrame("testing the menubar");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setContentPane(content);
content.add(new JLabel("My Label"));
window.pack();
window.setVisible(true);
}
public CTGContent() {
}
public CTGContent(JFrame window){
initializeBoard();
window.add(content);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater( new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
build();
}
});
}
}
It starts off the right size usually but then for some reason if I resize the window or something they change size with it. I need them to stay the same size no matter what. How can I do that?