|
1 | 1 | /* |
2 | | - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
27 | 27 | * @summary Printing UIDefaults throws NoSuchElementExcept |
28 | 28 | */ |
29 | 29 |
|
30 | | -import javax.swing.*; |
| 30 | +import java.awt.EventQueue; |
31 | 31 |
|
32 | | -public class bug4300666 { |
| 32 | +import javax.swing.UIDefaults; |
| 33 | +import javax.swing.UIManager; |
| 34 | +import javax.swing.UnsupportedLookAndFeelException; |
33 | 35 |
|
34 | | - public static void main(final String[] args) { |
35 | | - UIDefaults d = UIManager.getDefaults(); |
36 | | - d.toString(); |
| 36 | +import static javax.swing.UIManager.getInstalledLookAndFeels; |
| 37 | + |
| 38 | +public final class bug4300666 { |
| 39 | + |
| 40 | + public static void main(final String[] args) throws Exception { |
| 41 | + for (UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) { |
| 42 | + EventQueue.invokeAndWait(() -> setLookAndFeel(laf)); |
| 43 | + EventQueue.invokeAndWait(() -> { |
| 44 | + UIDefaults d = UIManager.getDefaults(); |
| 45 | + d.toString(); |
| 46 | + }); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) { |
| 51 | + try { |
| 52 | + UIManager.setLookAndFeel(laf.getClassName()); |
| 53 | + } catch (UnsupportedLookAndFeelException ignored) { |
| 54 | + System.out.println("Unsupported L&F: " + laf.getClassName()); |
| 55 | + } catch (ClassNotFoundException | InstantiationException |
| 56 | + | IllegalAccessException e) { |
| 57 | + throw new RuntimeException(e); |
| 58 | + } |
37 | 59 | } |
38 | 60 | } |
0 commit comments