I have 3 different panels in my JFrame and I am trying to update my 1st and 3rd panel in it each time I call a method which changes the text of the buttons within the panels. (Inside the 3rd panel (panel), there are 49 buttons in a 7 by 7 gridlayout)
The first panel (panel1) only has 1 jbutton that I am trying to update the text but it doesn't work either.
public void update() {
for (int c=0; c< Board.COLS; c++) {
for (int r=0; r< Board.ROWS; r++) {
JButton b = (JButton) panel.getComponent(r*7+c);
b.setOpaque(true);
b.setFocusable(false);
b.setPreferredSize(new Dimension(220,220));
b.setFont(b.getFont().deriveFont(Font.BOLD, b.getFont().getSize()*6));
b.setText("" + board.map[c][r].getType());
panel.add(b);
}
}
JButton extra = (JButton) (panel1.getComponent(0));
extra.setPreferredSize(new Dimension(200,100));
extra.setFont(extra.getFont().deriveFont(Font.BOLD, extra.getFont().getSize()*6));
extra.setText("" + board.oldTile.getType());
panel1.add(extra);
panel.repaint();
panel1.repaint();
}`
What I have here does some sort of refreshing on my JFrame but its going all over the place. The values are not where it should be and sometimes the JButtons are empty. I think the issue is getting the specific button inside a panel, and I don't know how to do that.
