I have a class that extends JPanel with several buttons on it. I would like to be able to set the font on all the buttons with one call to setFont(Font font); I defined the setFont method in the JPanel class as such:
public class MyPanel extends JPanel {
private JButton[] buttons = new JButton[10];
public MyPanel() {
for(int i = 0; i < 10; i++) {
buttons[i] = new JButton(""+i);
this.add(buttons[i]);
}
}
public void setFont(Font font) {
if(buttons != null) {
for(JButton b : buttons) {
b.setFont(font);
}
}
}
}
However, the font on the button never changes. I understand that setFont is called by the JPanel constructor, but I don't understand why, when I call it clearly AFTER the MyPanel object is created, the fonts aren't passed on to the buttons.
Thanks everyone!
Brent