JLabel[] table = new JLabel[]{lab1, lab2, ... ,lab125};
for (int i = 0 ; i < table.length ; i++)
table[i].setFont(thefont);
should do the trick
> [code]
> JLabel[] table = new JLabel[]{lab1, lab2, ...
> ,lab125};
> for (int i = 0 ; i < table.length ; i++)
>table.setFont(thefont);
> de]
>
> should do the trick
I my case label names are not so flexible. I mean they all have something meaningful names rather than just lab1,lab2...etc.
The intent is the same. Place all the items into an array and then loop through that array. Of course, if you mean all JLabels in the GUI (or starting from a specific Panel) then you can also do something like the following:
private void setFontAll(JComponent c) {
//Starting from anywhere
Container top = c.getTopLevelAncestor();
if (top instanceof javax.swing.JFrame) {
top = (JFrame) top.getContentPane();
} else if (top instanceof javax.swing.JApplet) {
top = (JApplet) top.getContentPane();
}
setRecursFont(top);
}
private void setRecursFont(Container c) {
for (Component sc : c.getComponents()) {
if (sc instanceof javax.swing.JLabel) {
(JLabel) sc.setFont(.....);
} else if (sc instanceof java.awt.Container) {
setRecursFont(sc);
}
}
}
This is not tested (even for syntax) and is just a thought, but you may wish to give it a try.