This is a piece of code which cause me problems.. i hope it's enough code to understand my problem.
frame.setLayout(new GridLayout(s, d));
grid = new JButton[d][s];
for (int x = 0; x < d; x++) {
for (int y = 0; y < s; y++) {
// grid[x][y] = new JButton(img); THIS WORKS BUT PUT AN IMAGE EVERYWHERE
frame.add(grid[x][y]);
grid[x][y].setText("ola");
grid[x][y].setHorizontalTextPosition(JButton.CENTER);
grid[x][y].setVerticalTextPosition(JButton.CENTER);
grid[x][y].setBorder(null);
}
}
// grid[5][5].setIcon(img); I WOULD LIKE TO DO SOMETHING LIKE THIS BUT IT GIVES ME NULLPOINTEREXEPTION
So I created a grid layout and then I want to put an image on some of the button which I added on the grid.
Thx for help and have a nice day :)


Sign In
Create Account


Back to top









