下面列出了怎么用javax.swing.plaf.metal.MetalLookAndFeel的API类实例代码及写法,或者点击链接到github查看源代码。
public static void main(String[] args) throws Exception {
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
SwingUtilities.invokeAndWait(bug7170310::createAndShowUI);
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
toolkit.realSync();
for (int i = 0; i < TABS_NUMBER; i++) {
SwingUtilities.invokeAndWait(bug7170310::addTab);
toolkit.realSync();
}
SwingUtilities.invokeAndWait(bug7170310::check);
if (exception != null) {
System.out.println("Test failed: " + exception.getMessage());
throw exception;
} else {
System.out.printf("Test passed");
}
} finally {
frame.dispose();
}
}
void test() {
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
throw new Error("Cannot set Metal LAF");
}
// Render text using background color
UIManager.put("textInactiveText", TEST_COLOR);
test(new JLabel(html));
test(new JButton(html));
JEditorPane pane = new JEditorPane("text/html", html);
pane.setDisabledTextColor(TEST_COLOR);
test(pane);
}
public static void main(String[] args) throws Exception {
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
SwingUtilities.invokeAndWait(bug7170310::createAndShowUI);
sync();
for (int i = 0; i < TABS_NUMBER; i++) {
SwingUtilities.invokeAndWait(bug7170310::addTab);
sync();
}
SwingUtilities.invokeAndWait(bug7170310::check);
if (exception != null) {
System.out.println("Test failed: " + exception.getMessage());
throw exception;
} else {
System.out.printf("Test passed");
}
} finally {
frame.dispose();
}
}
public static void main(String[] args) {
UIManager.put("swing.boldMetal", Boolean.FALSE);
JDialog.setDefaultLookAndFeelDecorated(true);
JFrame.setDefaultLookAndFeelDecorated(true);
Toolkit.getDefaultToolkit().setDynamicLayout(true);
System.setProperty("sun.awt.noerasebackground", "true");
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
System.out.println(
"Metal Look & Feel not supported on this platform. \n"
+ "Program Terminated");
System.exit(0);
}
JFrame frame = new MetalworksFrame();
frame.setVisible(true);
}
public static void main(String[] args) {
UIDefaults table= new MetalLookAndFeel().getDefaults();
test(table.get("ToolBar.rolloverBorder"),
"javax.swing.plaf.metal.MetalBorders$ButtonBorder",
"javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder");
test(table.get("ToolBar.nonrolloverBorder"),
"javax.swing.plaf.metal.MetalBorders$ButtonBorder",
"javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder");
test(table.get("RootPane.frameBorder"),
"javax.swing.plaf.metal.MetalBorders$FrameBorder");
test(table.get("RootPane.plainDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$DialogBorder");
test(table.get("RootPane.informationDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$DialogBorder");
test(table.get("RootPane.errorDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$ErrorDialogBorder");
test(table.get("RootPane.colorChooserDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
test(table.get("RootPane.fileChooserDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
test(table.get("RootPane.questionDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
test(table.get("RootPane.warningDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$WarningDialogBorder");
}
public static void main(String[] args) {
UIManager.put("swing.boldMetal", Boolean.FALSE);
JDialog.setDefaultLookAndFeelDecorated(true);
JFrame.setDefaultLookAndFeelDecorated(true);
Toolkit.getDefaultToolkit().setDynamicLayout(true);
System.setProperty("sun.awt.noerasebackground", "true");
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
System.out.println(
"Metal Look & Feel not supported on this platform. \n"
+ "Program Terminated");
System.exit(0);
}
JFrame frame = new MetalworksFrame();
frame.setVisible(true);
}
private static boolean isOceanTheme() {
if (!inSandbox) {
try {
java.lang.reflect.Field field = MetalLookAndFeel.class.getDeclaredField("currentTheme");
field.setAccessible(true);
Object theme = field.get(null);
return "javax.swing.plaf.metal.OceanTheme".equals(theme.getClass().getName());
} catch (Exception ex) {
// We're in a sandbox and can't access the field
inSandbox = true;
}
}
if (!checkedForOcean) {
checkedForOcean = true;
checkForOcean();
}
return usingOcean;
}
void test() {
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
throw new Error("Cannot set Metal LAF");
}
// Render text using background color
UIManager.put("textInactiveText", TEST_COLOR);
test(new JLabel(html));
test(new JButton(html));
JEditorPane pane = new JEditorPane("text/html", html);
pane.setDisabledTextColor(TEST_COLOR);
test(pane);
}
public static void main(String[] args) {
UIDefaults table= new MetalLookAndFeel().getDefaults();
test(table.get("ToolBar.rolloverBorder"),
"javax.swing.plaf.metal.MetalBorders$ButtonBorder",
"javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder");
test(table.get("ToolBar.nonrolloverBorder"),
"javax.swing.plaf.metal.MetalBorders$ButtonBorder",
"javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder");
test(table.get("RootPane.frameBorder"),
"javax.swing.plaf.metal.MetalBorders$FrameBorder");
test(table.get("RootPane.plainDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$DialogBorder");
test(table.get("RootPane.informationDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$DialogBorder");
test(table.get("RootPane.errorDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$ErrorDialogBorder");
test(table.get("RootPane.colorChooserDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
test(table.get("RootPane.fileChooserDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
test(table.get("RootPane.questionDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
test(table.get("RootPane.warningDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$WarningDialogBorder");
}
public static void main(String[] args) {
UIManager.put("swing.boldMetal", Boolean.FALSE);
JDialog.setDefaultLookAndFeelDecorated(true);
JFrame.setDefaultLookAndFeelDecorated(true);
Toolkit.getDefaultToolkit().setDynamicLayout(true);
System.setProperty("sun.awt.noerasebackground", "true");
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
System.out.println(
"Metal Look & Feel not supported on this platform. \n"
+ "Program Terminated");
System.exit(0);
}
JFrame frame = new MetalworksFrame();
frame.setVisible(true);
}
public static void main(String[] args) {
UIManager.put("swing.boldMetal", Boolean.FALSE);
JDialog.setDefaultLookAndFeelDecorated(true);
JFrame.setDefaultLookAndFeelDecorated(true);
Toolkit.getDefaultToolkit().setDynamicLayout(true);
System.setProperty("sun.awt.noerasebackground", "true");
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
System.out.println(
"Metal Look & Feel not supported on this platform. \n"
+ "Program Terminated");
System.exit(0);
}
JFrame frame = new MetalworksFrame();
frame.setVisible(true);
}
public static void main(String[] args) throws Exception {
tempDir = System.getProperty("java.io.tmpdir");
if (tempDir.length() == 0) { //'java.io.tmpdir' isn't guaranteed to be defined
tempDir = System.getProperty("user.home");
}
System.out.println("Temp directory: " + tempDir);
UIManager.setLookAndFeel(new MetalLookAndFeel());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
HackedFileChooser openChooser = new HackedFileChooser();
openChooser.setUI(new MetalFileChooserUI(openChooser));
openChooser.setCurrentDirectory(new File(tempDir));
}
});
}
void test() {
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
throw new Error("Cannot set Metal LAF");
}
// Render text using background color
UIManager.put("textInactiveText", TEST_COLOR);
test(new JLabel(html));
test(new JButton(html));
JEditorPane pane = new JEditorPane("text/html", html);
pane.setDisabledTextColor(TEST_COLOR);
test(pane);
}
public static void main(String[] args) {
UIDefaults table= new MetalLookAndFeel().getDefaults();
test(table.get("ToolBar.rolloverBorder"),
"javax.swing.plaf.metal.MetalBorders$ButtonBorder",
"javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder");
test(table.get("ToolBar.nonrolloverBorder"),
"javax.swing.plaf.metal.MetalBorders$ButtonBorder",
"javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder");
test(table.get("RootPane.frameBorder"),
"javax.swing.plaf.metal.MetalBorders$FrameBorder");
test(table.get("RootPane.plainDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$DialogBorder");
test(table.get("RootPane.informationDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$DialogBorder");
test(table.get("RootPane.errorDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$ErrorDialogBorder");
test(table.get("RootPane.colorChooserDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
test(table.get("RootPane.fileChooserDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
test(table.get("RootPane.questionDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
test(table.get("RootPane.warningDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$WarningDialogBorder");
}
/**
* {@link WebLookAndFeel} installation and uninstallation test through {@link UIManager}.
*/
@Test
public void installUninstallBasic ()
{
CoreSwingUtils.invokeAndWait ( new Runnable ()
{
@Override
public void run ()
{
try
{
// Installing WebLookAndFeel
UIManager.setLookAndFeel ( new WebLookAndFeel () );
// Uninstalling WebLookAndFeel
UIManager.setLookAndFeel ( MetalLookAndFeel.class.getCanonicalName () );
}
catch ( final Exception e )
{
throw new RuntimeException ( e );
}
}
} );
}
public static void main(String[] args) {
UIManager.put("swing.boldMetal", Boolean.FALSE);
JDialog.setDefaultLookAndFeelDecorated(true);
JFrame.setDefaultLookAndFeelDecorated(true);
Toolkit.getDefaultToolkit().setDynamicLayout(true);
System.setProperty("sun.awt.noerasebackground", "true");
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
System.out.println(
"Metal Look & Feel not supported on this platform. \n"
+ "Program Terminated");
System.exit(0);
}
JFrame frame = new MetalworksFrame();
frame.setVisible(true);
}
public static void main(String[] args) {
UIManager.put("swing.boldMetal", Boolean.FALSE);
JDialog.setDefaultLookAndFeelDecorated(true);
JFrame.setDefaultLookAndFeelDecorated(true);
Toolkit.getDefaultToolkit().setDynamicLayout(true);
System.setProperty("sun.awt.noerasebackground", "true");
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
System.out.println(
"Metal Look & Feel not supported on this platform. \n"
+ "Program Terminated");
System.exit(0);
}
JFrame frame = new MetalworksFrame();
frame.setVisible(true);
}
public static void main(String[] args) throws Exception {
tempDir = System.getProperty("java.io.tmpdir");
if (tempDir.length() == 0) { //'java.io.tmpdir' isn't guaranteed to be defined
tempDir = System.getProperty("user.home");
}
System.out.println("Temp directory: " + tempDir);
UIManager.setLookAndFeel(new MetalLookAndFeel());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
HackedFileChooser openChooser = new HackedFileChooser();
openChooser.setUI(new MetalFileChooserUI(openChooser));
openChooser.setCurrentDirectory(new File(tempDir));
}
});
}
public void testSinglePlatformInstall () throws IOException, UnsupportedLookAndFeelException {
UIManager.setLookAndFeel(new MetalLookAndFeel());
InstallerRegistry regs = InstallerRegistryAccessor.prepareForUnitTest(new GeneralPlatformInstall[] {
new FileBasedPlatformInstall ("FileBased1", Collections.<WizardDescriptor.Panel<WizardDescriptor>>singletonList(
new Panel ("FileBased1_panel1")
))
});
PlatformInstallIterator iterator = PlatformInstallIterator.create();
WizardDescriptor wd = new WizardDescriptor (iterator);
iterator.initialize(wd);
assertEquals("Invalid state", 1, iterator.getPanelIndex());
WizardDescriptor.Panel panel = iterator.current();
assertTrue ("Invalid panel",panel instanceof LocationChooser.Panel);
((JFileChooser)panel.getComponent()).setSelectedFile(this.getWorkDir()); //Select some folder
assertTrue ("LocationChooser is not valid after folder was selected",panel.isValid());
assertTrue ("Should have next panel",iterator.hasNext());
assertFalse ("Should not have previous panel", iterator.hasPrevious());
iterator.nextPanel();
assertEquals("Invalid state", 2, iterator.getPanelIndex());
panel = iterator.current();
assertEquals("Invalid panel","FileBased1_panel1",panel.getComponent().getName());
assertFalse ("Should not have next panel",iterator.hasNext());
assertTrue ("Should have previous panel", iterator.hasPrevious());
}
public static void main(String[] args) {
UIDefaults table= new MetalLookAndFeel().getDefaults();
test(table.get("ToolBar.rolloverBorder"),
"javax.swing.plaf.metal.MetalBorders$ButtonBorder",
"javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder");
test(table.get("ToolBar.nonrolloverBorder"),
"javax.swing.plaf.metal.MetalBorders$ButtonBorder",
"javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder");
test(table.get("RootPane.frameBorder"),
"javax.swing.plaf.metal.MetalBorders$FrameBorder");
test(table.get("RootPane.plainDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$DialogBorder");
test(table.get("RootPane.informationDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$DialogBorder");
test(table.get("RootPane.errorDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$ErrorDialogBorder");
test(table.get("RootPane.colorChooserDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
test(table.get("RootPane.fileChooserDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
test(table.get("RootPane.questionDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder");
test(table.get("RootPane.warningDialogBorder"),
"javax.swing.plaf.metal.MetalBorders$WarningDialogBorder");
}
public void actionPerformed(ActionEvent e) {
String numStr = e.getActionCommand();
MetalTheme selectedTheme = themes[Integer.parseInt(numStr)];
MetalLookAndFeel.setCurrentTheme(selectedTheme);
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} catch (Exception ex) {
System.out.println("Failed loading Metal");
System.out.println(ex);
}
}
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(new MetalLookAndFeel());
ThreadGroup group = new ThreadGroup("$$$");
Thread thread = new Thread(group, new Test6657026());
thread.start();
thread.join();
new JInternalFrame().setContentPane(new JPanel());
}
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(new MetalLookAndFeel());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
bug6559589.createGui();
}
});
}
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) throws Exception {
UIManager.setLookAndFeel(new MetalLookAndFeel());
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
System.out.println("The test passed");
}
public static void main(String[] args) throws Exception {
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
setUp();
doTest();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
throw new RuntimeException("Test failed");
}
}
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(new MetalLookAndFeel());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
bug6559589.createGui();
}
});
}
public static void main(String[] args) throws Exception {
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
setUp();
doTest();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
throw new RuntimeException("Test failed");
}
}
public static void main(String[] args) throws Exception {
toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
robot = new Robot();
robot.setAutoDelay(50);
UIManager.setLookAndFeel(new MetalLookAndFeel());
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
toolkit.realSync();
for (int i = 0; i < items.length; i++) {
// Open popup
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
toolkit.realSync();
Point point = getItemPointToClick(i);
robot.mouseMove(point.x, point.y);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
toolkit.realSync();
if (i != getSelectedIndex()) {
throw new RuntimeException("Test Failed! Incorrect value of selected index = " + getSelectedIndex() +
", expected value = " + i);
}
}
}
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);
}