Help please

I have 125 labels and other fields. Now i want to set font style as bold to all these 125 labels. Is it possible to set all these labels font style to bold with single statement. I mean is there any method to do this job.
[228 byte] By [ArpanaKa] at [2007-11-27 1:26:22]
# 1

JLabel[] table = new JLabel[]{lab1, lab2, ... ,lab125};

for (int i = 0 ; i < table.length ; i++)

table[i].setFont(thefont);

should do the trick

calvino_inda at 2007-7-12 0:20:51 > top of Java-index,Java Essentials,Java Programming...
# 2

> [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.

ArpanaKa at 2007-7-12 0:20:51 > top of Java-index,Java Essentials,Java Programming...
# 3

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.

masijade.a at 2007-7-12 0:20:51 > top of Java-index,Java Essentials,Java Programming...
# 4
Thanks for your time. It worked.
ArpanaKa at 2007-7-12 0:20:51 > top of Java-index,Java Essentials,Java Programming...