Java by API/javax.swing/UIDefaults — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:21, 31 мая 2010
Содержание
- 1 implements UIDefaults.ActiveValue
- 2 UIDefaults: getBoolean(Object key)
- 3 UIDefaults: getColor(Object key)
- 4 UIDefaults: getDimension(Object key)
- 5 UIDefaults: getFont(Object key)
- 6 UIDefaults: getIcon(Object key)
- 7 UIDefaults: getInsets(Object key)
- 8 UIDefaults: getInt(Object key)
- 9 UIDefaults.ProxyLazyValue(String c, Object[] o)
implements UIDefaults.ActiveValue
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
public class MainClass {
public static void main(String args[]) {
final String LABEL_FACTORY = "LabelFactory";
JFrame frame = new JFrame("Active Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
UIManager.put(LABEL_FACTORY, new ActiveLabel());
final JPanel panel = new JPanel();
JButton button = new JButton("Get");
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
JLabel label = (JLabel)UIManager.get(LABEL_FACTORY);
panel.add(label);
panel.revalidate();
}
};
button.addActionListener(actionListener);
frame.add(panel, BorderLayout.CENTER);
frame.add(button, BorderLayout.SOUTH);
frame.setSize(200, 200);
frame.setVisible(true); }
}
class ActiveLabel implements UIDefaults.ActiveValue {
private int counter = 0;
public Object createValue(UIDefaults defaults) {
JLabel label = new JLabel(""+counter++);
return label;
}
}
UIDefaults: getBoolean(Object key)
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.Icon;
import javax.swing.InputMap;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.text.JTextComponent;
public class Main {
public static void main(String[] argv) {
UIDefaults uidefs = UIManager.getLookAndFeelDefaults();
String[] keys = (String[]) uidefs.keySet().toArray(new String[0]);
for (int i = 0; i < keys.length; i++) {
Object v = uidefs.get(keys[i]);
if (v instanceof Integer) {
int intVal = uidefs.getInt(keys[i]);
} else if (v instanceof Boolean) {
boolean boolVal = uidefs.getBoolean(keys[i]);
} else if (v instanceof String) {
String strVal = uidefs.getString(keys[i]);
} else if (v instanceof Dimension) {
Dimension dimVal = uidefs.getDimension(keys[i]);
} else if (v instanceof Insets) {
Insets insetsVal = uidefs.getInsets(keys[i]);
} else if (v instanceof Color) {
Color colorVal = uidefs.getColor(keys[i]);
} else if (v instanceof Font) {
Font fontVal = uidefs.getFont(keys[i]);
} else if (v instanceof Border) {
Border borderVal = uidefs.getBorder(keys[i]);
} else if (v instanceof Icon) {
Icon iconVal = uidefs.getIcon(keys[i]);
} else if (v instanceof javax.swing.text.JTextComponent.KeyBinding[]) {
JTextComponent.KeyBinding[] keyBindsVal = (JTextComponent.KeyBinding[]) uidefs
.get(keys[i]);
} else if (v instanceof InputMap) {
InputMap imapVal = (InputMap) uidefs.get(keys[i]);
} else {
System.out.println("Unknown type");
}
}
}
}
UIDefaults: getColor(Object key)
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.Icon;
import javax.swing.InputMap;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.text.JTextComponent;
public class Main {
public static void main(String[] argv) {
UIDefaults uidefs = UIManager.getLookAndFeelDefaults();
String[] keys = (String[]) uidefs.keySet().toArray(new String[0]);
for (int i = 0; i < keys.length; i++) {
Object v = uidefs.get(keys[i]);
if (v instanceof Integer) {
int intVal = uidefs.getInt(keys[i]);
} else if (v instanceof Boolean) {
boolean boolVal = uidefs.getBoolean(keys[i]);
} else if (v instanceof String) {
String strVal = uidefs.getString(keys[i]);
} else if (v instanceof Dimension) {
Dimension dimVal = uidefs.getDimension(keys[i]);
} else if (v instanceof Insets) {
Insets insetsVal = uidefs.getInsets(keys[i]);
} else if (v instanceof Color) {
Color colorVal = uidefs.getColor(keys[i]);
} else if (v instanceof Font) {
Font fontVal = uidefs.getFont(keys[i]);
} else if (v instanceof Border) {
Border borderVal = uidefs.getBorder(keys[i]);
} else if (v instanceof Icon) {
Icon iconVal = uidefs.getIcon(keys[i]);
} else if (v instanceof javax.swing.text.JTextComponent.KeyBinding[]) {
JTextComponent.KeyBinding[] keyBindsVal = (JTextComponent.KeyBinding[]) uidefs
.get(keys[i]);
} else if (v instanceof InputMap) {
InputMap imapVal = (InputMap) uidefs.get(keys[i]);
} else {
System.out.println("Unknown type");
}
}
}
}
UIDefaults: getDimension(Object key)
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.Icon;
import javax.swing.InputMap;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.text.JTextComponent;
public class Main {
public static void main(String[] argv) {
UIDefaults uidefs = UIManager.getLookAndFeelDefaults();
String[] keys = (String[]) uidefs.keySet().toArray(new String[0]);
for (int i = 0; i < keys.length; i++) {
Object v = uidefs.get(keys[i]);
if (v instanceof Integer) {
int intVal = uidefs.getInt(keys[i]);
} else if (v instanceof Boolean) {
boolean boolVal = uidefs.getBoolean(keys[i]);
} else if (v instanceof String) {
String strVal = uidefs.getString(keys[i]);
} else if (v instanceof Dimension) {
Dimension dimVal = uidefs.getDimension(keys[i]);
} else if (v instanceof Insets) {
Insets insetsVal = uidefs.getInsets(keys[i]);
} else if (v instanceof Color) {
Color colorVal = uidefs.getColor(keys[i]);
} else if (v instanceof Font) {
Font fontVal = uidefs.getFont(keys[i]);
} else if (v instanceof Border) {
Border borderVal = uidefs.getBorder(keys[i]);
} else if (v instanceof Icon) {
Icon iconVal = uidefs.getIcon(keys[i]);
} else if (v instanceof javax.swing.text.JTextComponent.KeyBinding[]) {
JTextComponent.KeyBinding[] keyBindsVal = (JTextComponent.KeyBinding[]) uidefs
.get(keys[i]);
} else if (v instanceof InputMap) {
InputMap imapVal = (InputMap) uidefs.get(keys[i]);
} else {
System.out.println("Unknown type");
}
}
}
}
UIDefaults: getFont(Object key)
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.Icon;
import javax.swing.InputMap;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.text.JTextComponent;
public class Main {
public static void main(String[] argv) {
UIDefaults uidefs = UIManager.getLookAndFeelDefaults();
String[] keys = (String[]) uidefs.keySet().toArray(new String[0]);
for (int i = 0; i < keys.length; i++) {
Object v = uidefs.get(keys[i]);
if (v instanceof Integer) {
int intVal = uidefs.getInt(keys[i]);
} else if (v instanceof Boolean) {
boolean boolVal = uidefs.getBoolean(keys[i]);
} else if (v instanceof String) {
String strVal = uidefs.getString(keys[i]);
} else if (v instanceof Dimension) {
Dimension dimVal = uidefs.getDimension(keys[i]);
} else if (v instanceof Insets) {
Insets insetsVal = uidefs.getInsets(keys[i]);
} else if (v instanceof Color) {
Color colorVal = uidefs.getColor(keys[i]);
} else if (v instanceof Font) {
Font fontVal = uidefs.getFont(keys[i]);
} else if (v instanceof Border) {
Border borderVal = uidefs.getBorder(keys[i]);
} else if (v instanceof Icon) {
Icon iconVal = uidefs.getIcon(keys[i]);
} else if (v instanceof javax.swing.text.JTextComponent.KeyBinding[]) {
JTextComponent.KeyBinding[] keyBindsVal = (JTextComponent.KeyBinding[]) uidefs
.get(keys[i]);
} else if (v instanceof InputMap) {
InputMap imapVal = (InputMap) uidefs.get(keys[i]);
} else {
System.out.println("Unknown type");
}
}
}
}
UIDefaults: getIcon(Object key)
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.Icon;
import javax.swing.InputMap;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.text.JTextComponent;
public class Main {
public static void main(String[] argv) {
UIDefaults uidefs = UIManager.getLookAndFeelDefaults();
String[] keys = (String[]) uidefs.keySet().toArray(new String[0]);
for (int i = 0; i < keys.length; i++) {
Object v = uidefs.get(keys[i]);
if (v instanceof Integer) {
int intVal = uidefs.getInt(keys[i]);
} else if (v instanceof Boolean) {
boolean boolVal = uidefs.getBoolean(keys[i]);
} else if (v instanceof String) {
String strVal = uidefs.getString(keys[i]);
} else if (v instanceof Dimension) {
Dimension dimVal = uidefs.getDimension(keys[i]);
} else if (v instanceof Insets) {
Insets insetsVal = uidefs.getInsets(keys[i]);
} else if (v instanceof Color) {
Color colorVal = uidefs.getColor(keys[i]);
} else if (v instanceof Font) {
Font fontVal = uidefs.getFont(keys[i]);
} else if (v instanceof Border) {
Border borderVal = uidefs.getBorder(keys[i]);
} else if (v instanceof Icon) {
Icon iconVal = uidefs.getIcon(keys[i]);
} else if (v instanceof javax.swing.text.JTextComponent.KeyBinding[]) {
JTextComponent.KeyBinding[] keyBindsVal = (JTextComponent.KeyBinding[]) uidefs
.get(keys[i]);
} else if (v instanceof InputMap) {
InputMap imapVal = (InputMap) uidefs.get(keys[i]);
} else {
System.out.println("Unknown type");
}
}
}
}
UIDefaults: getInsets(Object key)
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.Icon;
import javax.swing.InputMap;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.text.JTextComponent;
public class Main {
public static void main(String[] argv) {
UIDefaults uidefs = UIManager.getLookAndFeelDefaults();
String[] keys = (String[]) uidefs.keySet().toArray(new String[0]);
for (int i = 0; i < keys.length; i++) {
Object v = uidefs.get(keys[i]);
if (v instanceof Integer) {
int intVal = uidefs.getInt(keys[i]);
} else if (v instanceof Boolean) {
boolean boolVal = uidefs.getBoolean(keys[i]);
} else if (v instanceof String) {
String strVal = uidefs.getString(keys[i]);
} else if (v instanceof Dimension) {
Dimension dimVal = uidefs.getDimension(keys[i]);
} else if (v instanceof Insets) {
Insets insetsVal = uidefs.getInsets(keys[i]);
} else if (v instanceof Color) {
Color colorVal = uidefs.getColor(keys[i]);
} else if (v instanceof Font) {
Font fontVal = uidefs.getFont(keys[i]);
} else if (v instanceof Border) {
Border borderVal = uidefs.getBorder(keys[i]);
} else if (v instanceof Icon) {
Icon iconVal = uidefs.getIcon(keys[i]);
} else if (v instanceof javax.swing.text.JTextComponent.KeyBinding[]) {
JTextComponent.KeyBinding[] keyBindsVal = (JTextComponent.KeyBinding[]) uidefs
.get(keys[i]);
} else if (v instanceof InputMap) {
InputMap imapVal = (InputMap) uidefs.get(keys[i]);
} else {
System.out.println("Unknown type");
}
}
}
}
UIDefaults: getInt(Object key)
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.Icon;
import javax.swing.InputMap;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.text.JTextComponent;
public class Main {
public static void main(String[] argv) {
UIDefaults uidefs = UIManager.getLookAndFeelDefaults();
String[] keys = (String[]) uidefs.keySet().toArray(new String[0]);
for (int i = 0; i < keys.length; i++) {
Object v = uidefs.get(keys[i]);
if (v instanceof Integer) {
int intVal = uidefs.getInt(keys[i]);
} else if (v instanceof Boolean) {
boolean boolVal = uidefs.getBoolean(keys[i]);
} else if (v instanceof String) {
String strVal = uidefs.getString(keys[i]);
} else if (v instanceof Dimension) {
Dimension dimVal = uidefs.getDimension(keys[i]);
} else if (v instanceof Insets) {
Insets insetsVal = uidefs.getInsets(keys[i]);
} else if (v instanceof Color) {
Color colorVal = uidefs.getColor(keys[i]);
} else if (v instanceof Font) {
Font fontVal = uidefs.getFont(keys[i]);
} else if (v instanceof Border) {
Border borderVal = uidefs.getBorder(keys[i]);
} else if (v instanceof Icon) {
Icon iconVal = uidefs.getIcon(keys[i]);
} else if (v instanceof javax.swing.text.JTextComponent.KeyBinding[]) {
JTextComponent.KeyBinding[] keyBindsVal = (JTextComponent.KeyBinding[]) uidefs
.get(keys[i]);
} else if (v instanceof InputMap) {
InputMap imapVal = (InputMap) uidefs.get(keys[i]);
} else {
System.out.println("Unknown type");
}
}
}
}
UIDefaults.ProxyLazyValue(String c, Object[] o)
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.LookAndFeel;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
public class MainClass {
public static void main(String args[]) {
JFrame frame = new JFrame("Lazy Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Object iconObject = LookAndFeel.makeIcon(MainClass.class, "yourImage.gif");
UIManager.put("Tree.leafIcon", iconObject);
Integer fifteen = new Integer(15);
Object lazyArgs[] = new Object[] { Color.GREEN, Boolean.TRUE, fifteen, fifteen };
Object lazyDiamond = new UIDefaults.ProxyLazyValue("DiamondIcon", lazyArgs);
UIManager.put("Tree.openIcon", lazyDiamond);
JTree tree = new JTree();
JScrollPane scrollPane = new JScrollPane(tree);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setSize(200, 200);
frame.setVisible(true);
}
}