下面列出了怎么用javax.swing.plaf.metal.DefaultMetalTheme的API类实例代码及写法,或者点击链接到github查看源代码。
public static void main(String[] args) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JFrame frame = new JFrame();
frame.setContentPane(new TestPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JFrame frame = new JFrame();
frame.setContentPane(new TestPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JFrame frame = new JFrame();
frame.setContentPane(new TestPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JFrame frame = new JFrame();
frame.setContentPane(new TestPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JFrame frame = new JFrame();
frame.setContentPane(new TestPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JFrame frame = new JFrame();
frame.setContentPane(new TestPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JFrame frame = new JFrame();
frame.setContentPane(new TestPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JFrame frame = new JFrame();
frame.setContentPane(new TestPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JFrame frame = new JFrame();
frame.setContentPane(new TestPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JFrame frame = new JFrame();
frame.setContentPane(new TestPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JFrame frame = new JFrame();
frame.setContentPane(new TestPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JFrame frame = new JFrame();
frame.setContentPane(new TestPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JFrame frame = new JFrame();
frame.setContentPane(new TestPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
/**
* Creates a JRadioButtonMenuItem for the Themes menu
*/
public JMenuItem createThemesMenuItem(JMenu menu, String label, String mnemonic,
String accessibleDescription, DefaultMetalTheme theme) {
JRadioButtonMenuItem mi = (JRadioButtonMenuItem) menu.add(new JRadioButtonMenuItem(getString(label)));
themesMenuGroup.add(mi);
mi.setMnemonic(getMnemonic(mnemonic));
mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription));
mi.addActionListener(new ChangeThemeAction(this, theme));
return mi;
}
protected void buildMenus() {
menuBar = new JMenuBar();
menuBar.setOpaque(true);
JMenu file = buildFileMenu();
JMenu edit = buildEditMenu();
JMenu views = buildViewsMenu();
JMenu speed = buildSpeedMenu();
JMenu help = buildHelpMenu();
// load a theme from a text file
MetalTheme myTheme = null;
try {
InputStream istream = getClass().getResourceAsStream(
"/resources/MyTheme.theme");
myTheme = new PropertiesMetalTheme(istream);
} catch (NullPointerException e) {
System.out.println(e);
}
// build an array of themes
MetalTheme[] themes = { new OceanTheme(),
new DefaultMetalTheme(),
new GreenMetalTheme(),
new AquaMetalTheme(),
new KhakiMetalTheme(),
new DemoMetalTheme(),
new ContrastMetalTheme(),
new BigContrastMetalTheme(),
myTheme };
// put the themes in a menu
JMenu themeMenu = new MetalThemeMenu("Theme", themes);
menuBar.add(file);
menuBar.add(edit);
menuBar.add(views);
menuBar.add(themeMenu);
menuBar.add(speed);
menuBar.add(help);
setJMenuBar(menuBar);
}
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JComponent component = new JLabel();
Icon horizontalThumbIcon = UIManager.getIcon("Slider.horizontalThumbIcon");
Icon verticalThumbIcon = UIManager.getIcon("Slider.verticalThumbIcon");
Graphics g = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR).getGraphics();
horizontalThumbIcon.paintIcon(component, g, 0, 0);
verticalThumbIcon.paintIcon(component, g, 0, 0);
}
});
}
protected void buildMenus() {
menuBar = new JMenuBar();
menuBar.setOpaque(true);
JMenu file = buildFileMenu();
JMenu edit = buildEditMenu();
JMenu views = buildViewsMenu();
JMenu speed = buildSpeedMenu();
JMenu help = buildHelpMenu();
// load a theme from a text file
MetalTheme myTheme = null;
try {
InputStream istream = getClass().getResourceAsStream(
"/resources/MyTheme.theme");
myTheme = new PropertiesMetalTheme(istream);
} catch (NullPointerException e) {
System.out.println(e);
}
// build an array of themes
MetalTheme[] themes = { new OceanTheme(),
new DefaultMetalTheme(),
new GreenMetalTheme(),
new AquaMetalTheme(),
new KhakiMetalTheme(),
new DemoMetalTheme(),
new ContrastMetalTheme(),
new BigContrastMetalTheme(),
myTheme };
// put the themes in a menu
JMenu themeMenu = new MetalThemeMenu("Theme", themes);
menuBar.add(file);
menuBar.add(edit);
menuBar.add(views);
menuBar.add(themeMenu);
menuBar.add(speed);
menuBar.add(help);
setJMenuBar(menuBar);
}
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JComponent component = new JLabel();
Icon horizontalThumbIcon = UIManager.getIcon("Slider.horizontalThumbIcon");
Icon verticalThumbIcon = UIManager.getIcon("Slider.verticalThumbIcon");
Graphics g = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR).getGraphics();
horizontalThumbIcon.paintIcon(component, g, 0, 0);
verticalThumbIcon.paintIcon(component, g, 0, 0);
}
});
}
protected void buildMenus() {
menuBar = new JMenuBar();
menuBar.setOpaque(true);
JMenu file = buildFileMenu();
JMenu edit = buildEditMenu();
JMenu views = buildViewsMenu();
JMenu speed = buildSpeedMenu();
JMenu help = buildHelpMenu();
// load a theme from a text file
MetalTheme myTheme = null;
try {
InputStream istream = getClass().getResourceAsStream(
"/resources/MyTheme.theme");
myTheme = new PropertiesMetalTheme(istream);
} catch (NullPointerException e) {
System.out.println(e);
}
// build an array of themes
MetalTheme[] themes = { new OceanTheme(),
new DefaultMetalTheme(),
new GreenMetalTheme(),
new AquaMetalTheme(),
new KhakiMetalTheme(),
new DemoMetalTheme(),
new ContrastMetalTheme(),
new BigContrastMetalTheme(),
myTheme };
// put the themes in a menu
JMenu themeMenu = new MetalThemeMenu("Theme", themes);
menuBar.add(file);
menuBar.add(edit);
menuBar.add(views);
menuBar.add(themeMenu);
menuBar.add(speed);
menuBar.add(help);
setJMenuBar(menuBar);
}
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JComponent component = new JLabel();
Icon horizontalThumbIcon = UIManager.getIcon("Slider.horizontalThumbIcon");
Icon verticalThumbIcon = UIManager.getIcon("Slider.verticalThumbIcon");
Graphics g = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR).getGraphics();
horizontalThumbIcon.paintIcon(component, g, 0, 0);
verticalThumbIcon.paintIcon(component, g, 0, 0);
}
});
}
protected void buildMenus() {
menuBar = new JMenuBar();
menuBar.setOpaque(true);
JMenu file = buildFileMenu();
JMenu edit = buildEditMenu();
JMenu views = buildViewsMenu();
JMenu speed = buildSpeedMenu();
JMenu help = buildHelpMenu();
// load a theme from a text file
MetalTheme myTheme = null;
try {
InputStream istream = getClass().getResourceAsStream(
"/resources/MyTheme.theme");
myTheme = new PropertiesMetalTheme(istream);
} catch (NullPointerException e) {
System.out.println(e);
}
// build an array of themes
MetalTheme[] themes = { new OceanTheme(),
new DefaultMetalTheme(),
new GreenMetalTheme(),
new AquaMetalTheme(),
new KhakiMetalTheme(),
new DemoMetalTheme(),
new ContrastMetalTheme(),
new BigContrastMetalTheme(),
myTheme };
// put the themes in a menu
JMenu themeMenu = new MetalThemeMenu("Theme", themes);
menuBar.add(file);
menuBar.add(edit);
menuBar.add(views);
menuBar.add(themeMenu);
menuBar.add(speed);
menuBar.add(help);
setJMenuBar(menuBar);
}
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JComponent component = new JLabel();
Icon horizontalThumbIcon = UIManager.getIcon("Slider.horizontalThumbIcon");
Icon verticalThumbIcon = UIManager.getIcon("Slider.verticalThumbIcon");
Graphics g = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR).getGraphics();
horizontalThumbIcon.paintIcon(component, g, 0, 0);
verticalThumbIcon.paintIcon(component, g, 0, 0);
}
});
}
protected void buildMenus() {
menuBar = new JMenuBar();
menuBar.setOpaque(true);
JMenu file = buildFileMenu();
JMenu edit = buildEditMenu();
JMenu views = buildViewsMenu();
JMenu speed = buildSpeedMenu();
JMenu help = buildHelpMenu();
// load a theme from a text file
MetalTheme myTheme = null;
try {
InputStream istream = getClass().getResourceAsStream(
"/resources/MyTheme.theme");
myTheme = new PropertiesMetalTheme(istream);
} catch (NullPointerException e) {
System.out.println(e);
}
// build an array of themes
MetalTheme[] themes = { new OceanTheme(),
new DefaultMetalTheme(),
new GreenMetalTheme(),
new AquaMetalTheme(),
new KhakiMetalTheme(),
new DemoMetalTheme(),
new ContrastMetalTheme(),
new BigContrastMetalTheme(),
myTheme };
// put the themes in a menu
JMenu themeMenu = new MetalThemeMenu("Theme", themes);
menuBar.add(file);
menuBar.add(edit);
menuBar.add(views);
menuBar.add(themeMenu);
menuBar.add(speed);
menuBar.add(help);
setJMenuBar(menuBar);
}
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JComponent component = new JLabel();
Icon horizontalThumbIcon = UIManager.getIcon("Slider.horizontalThumbIcon");
Icon verticalThumbIcon = UIManager.getIcon("Slider.verticalThumbIcon");
Graphics g = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR).getGraphics();
horizontalThumbIcon.paintIcon(component, g, 0, 0);
verticalThumbIcon.paintIcon(component, g, 0, 0);
}
});
}
protected void buildMenus() {
menuBar = new JMenuBar();
menuBar.setOpaque(true);
JMenu file = buildFileMenu();
JMenu edit = buildEditMenu();
JMenu views = buildViewsMenu();
JMenu speed = buildSpeedMenu();
JMenu help = buildHelpMenu();
// load a theme from a text file
MetalTheme myTheme = null;
try {
InputStream istream = getClass().getResourceAsStream(
"/resources/MyTheme.theme");
myTheme = new PropertiesMetalTheme(istream);
} catch (NullPointerException e) {
System.out.println(e);
}
// build an array of themes
MetalTheme[] themes = { new OceanTheme(),
new DefaultMetalTheme(),
new GreenMetalTheme(),
new AquaMetalTheme(),
new KhakiMetalTheme(),
new DemoMetalTheme(),
new ContrastMetalTheme(),
new BigContrastMetalTheme(),
myTheme };
// put the themes in a menu
JMenu themeMenu = new MetalThemeMenu("Theme", themes);
menuBar.add(file);
menuBar.add(edit);
menuBar.add(views);
menuBar.add(themeMenu);
menuBar.add(speed);
menuBar.add(help);
setJMenuBar(menuBar);
}
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JComponent component = new JLabel();
Icon horizontalThumbIcon = UIManager.getIcon("Slider.horizontalThumbIcon");
Icon verticalThumbIcon = UIManager.getIcon("Slider.verticalThumbIcon");
Graphics g = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR).getGraphics();
horizontalThumbIcon.paintIcon(component, g, 0, 0);
verticalThumbIcon.paintIcon(component, g, 0, 0);
}
});
}
protected void buildMenus() {
menuBar = new JMenuBar();
menuBar.setOpaque(true);
JMenu file = buildFileMenu();
JMenu edit = buildEditMenu();
JMenu views = buildViewsMenu();
JMenu speed = buildSpeedMenu();
JMenu help = buildHelpMenu();
// load a theme from a text file
MetalTheme myTheme = null;
try {
InputStream istream = getClass().getResourceAsStream(
"/resources/MyTheme.theme");
myTheme = new PropertiesMetalTheme(istream);
} catch (NullPointerException e) {
System.out.println(e);
}
// build an array of themes
MetalTheme[] themes = { new OceanTheme(),
new DefaultMetalTheme(),
new GreenMetalTheme(),
new AquaMetalTheme(),
new KhakiMetalTheme(),
new DemoMetalTheme(),
new ContrastMetalTheme(),
new BigContrastMetalTheme(),
myTheme };
// put the themes in a menu
JMenu themeMenu = new MetalThemeMenu("Theme", themes);
menuBar.add(file);
menuBar.add(edit);
menuBar.add(views);
menuBar.add(themeMenu);
menuBar.add(speed);
menuBar.add(help);
setJMenuBar(menuBar);
}
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JComponent component = new JLabel();
Icon horizontalThumbIcon = UIManager.getIcon("Slider.horizontalThumbIcon");
Icon verticalThumbIcon = UIManager.getIcon("Slider.verticalThumbIcon");
Graphics g = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR).getGraphics();
horizontalThumbIcon.paintIcon(component, g, 0, 0);
verticalThumbIcon.paintIcon(component, g, 0, 0);
}
});
}
protected void buildMenus() {
menuBar = new JMenuBar();
menuBar.setOpaque(true);
JMenu file = buildFileMenu();
JMenu edit = buildEditMenu();
JMenu views = buildViewsMenu();
JMenu speed = buildSpeedMenu();
JMenu help = buildHelpMenu();
// load a theme from a text file
MetalTheme myTheme = null;
try {
InputStream istream = getClass().getResourceAsStream(
"/resources/MyTheme.theme");
myTheme = new PropertiesMetalTheme(istream);
} catch (NullPointerException e) {
System.out.println(e);
}
// build an array of themes
MetalTheme[] themes = { new OceanTheme(),
new DefaultMetalTheme(),
new GreenMetalTheme(),
new AquaMetalTheme(),
new KhakiMetalTheme(),
new DemoMetalTheme(),
new ContrastMetalTheme(),
new BigContrastMetalTheme(),
myTheme };
// put the themes in a menu
JMenu themeMenu = new MetalThemeMenu("Theme", themes);
menuBar.add(file);
menuBar.add(edit);
menuBar.add(views);
menuBar.add(themeMenu);
menuBar.add(speed);
menuBar.add(help);
setJMenuBar(menuBar);
}
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
JComponent component = new JLabel();
Icon horizontalThumbIcon = UIManager.getIcon("Slider.horizontalThumbIcon");
Icon verticalThumbIcon = UIManager.getIcon("Slider.verticalThumbIcon");
Graphics g = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR).getGraphics();
horizontalThumbIcon.paintIcon(component, g, 0, 0);
verticalThumbIcon.paintIcon(component, g, 0, 0);
}
});
}