1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
private static void changeFont(int size) {
if (size < MIN_SIZE_FONT) {
size = MIN_SIZE_FONT;
}
displayProperties(size);
refreshAllComp(frame);
}
private static void refreshAllComp(Component component) {
if (null == component) {
return;
}
System.out.println("la classe du composant est " + component.getClass());
if (component instanceof JComponent) {
System.out.println(" 1 la classe du composant est " + component.getClass());
JComponent comp = (JComponent) component;
if (null != comp.getComponents()) {
for (Component c : comp.getComponents()) {
refreshAllComp(c);
}
}
refreshComponent(comp);
} else if (component instanceof Container) {
System.out.println(" 2 la classe du composant est " + component.getClass());
Container container = (Container) component;
if (null != container.getComponents()) {
for (Component comp : container.getComponents()) {
refreshAllComp(comp);
}
}
refreshComponent(component);
}
}
private static void displayProperties(int size) {
Enumeration<Object> e = UIManager.getDefaults().keys();
while (e.hasMoreElements()) {
String key = e.nextElement().toString();
if (key.endsWith(".font")) {
putFont(key, size);
}
}
}
private static void putFont(String name, int size) {
UIManager.put(name, Font.decode(IFIELD_FONT + size));
} |
Partager