< prev index next >

test/javax/swing/UI/UnninstallUIMemoryLeaks/UnninstallUIMemoryLeaks.java

Print this page
rev 17561 : 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
Summary: Add new keyword 'printer'. Some minor test fixes to show headless exception. Add some @requires windows.


  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.awt.EventQueue;
  25 import java.awt.FlowLayout;
  26 
  27 import javax.swing.*;
  28 import javax.swing.UIManager.LookAndFeelInfo;
  29 
  30 import static javax.swing.UIManager.getInstalledLookAndFeels;
  31 
  32 /**
  33  * @test

  34  * @bug 8134947
  35  * @author Sergey Bylokhov
  36  * @run main/timeout=300/othervm -Xmx12m -XX:+HeapDumpOnOutOfMemoryError UnninstallUIMemoryLeaks
  37  */
  38 public final class UnninstallUIMemoryLeaks {
  39 
  40     private static JFrame frame;
  41 
  42     public static void main(final String[] args) throws Exception {
  43         try {
  44             createGUI();
  45             for (final LookAndFeelInfo laf : getInstalledLookAndFeels()) {
  46                 final String name = laf.getName();
  47                 if (name.contains("OS X") || name.contains("Metal")) {
  48                     SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
  49                     SwingUtilities.invokeAndWait(() -> {
  50                         for (int i = 0; i < 4000; ++i) {
  51                             SwingUtilities.updateComponentTreeUI(frame);
  52                         }
  53                     });
  54                 }
  55             }
  56         } finally {
  57             EventQueue.invokeAndWait(() -> frame.dispose());
  58         }
  59     }
  60 
  61     private static void createGUI() throws Exception {
  62         EventQueue.invokeAndWait(() -> {
  63             frame = new JFrame();
  64             frame.setLayout(new FlowLayout());
  65 
  66             frame.add(new JButton("JButton"));
  67             frame.add(new JCheckBox("JCheckBox"));
  68             frame.add(new JComboBox<>());
  69             frame.add(new JEditorPane());
  70             frame.add(new JFormattedTextField("JFormattedTextField"));
  71             frame.add(new JLabel("label"));
  72             frame.add(new JPanel());
  73             frame.add(new JPasswordField("JPasswordField"));
  74             frame.add(new JProgressBar());
  75             frame.add(new JRadioButton("JRadioButton"));
  76             frame.add(new JScrollBar());
  77             frame.add(new JScrollPane());




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.awt.EventQueue;
  25 import java.awt.FlowLayout;
  26 
  27 import javax.swing.*;
  28 import javax.swing.UIManager.LookAndFeelInfo;
  29 
  30 import static javax.swing.UIManager.getInstalledLookAndFeels;
  31 
  32 /**
  33  * @test
  34  * @key headful
  35  * @bug 8134947
  36  * @author Sergey Bylokhov
  37  * @run main/timeout=300/othervm -Xmx12m -XX:+HeapDumpOnOutOfMemoryError UnninstallUIMemoryLeaks
  38  */
  39 public final class UnninstallUIMemoryLeaks {
  40 
  41     private static JFrame frame;
  42 
  43     public static void main(final String[] args) throws Exception {
  44         try {
  45             createGUI();
  46             for (final LookAndFeelInfo laf : getInstalledLookAndFeels()) {
  47                 final String name = laf.getName();
  48                 if (name.contains("OS X") || name.contains("Metal")) {
  49                     SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
  50                     SwingUtilities.invokeAndWait(() -> {
  51                         for (int i = 0; i < 4000; ++i) {
  52                             SwingUtilities.updateComponentTreeUI(frame);
  53                         }
  54                     });
  55                 }
  56             }
  57         } finally {
  58             if (frame != null) { EventQueue.invokeAndWait(() -> frame.dispose()); }
  59         }
  60     }
  61 
  62     private static void createGUI() throws Exception {
  63         EventQueue.invokeAndWait(() -> {
  64             frame = new JFrame();
  65             frame.setLayout(new FlowLayout());
  66 
  67             frame.add(new JButton("JButton"));
  68             frame.add(new JCheckBox("JCheckBox"));
  69             frame.add(new JComboBox<>());
  70             frame.add(new JEditorPane());
  71             frame.add(new JFormattedTextField("JFormattedTextField"));
  72             frame.add(new JLabel("label"));
  73             frame.add(new JPanel());
  74             frame.add(new JPasswordField("JPasswordField"));
  75             frame.add(new JProgressBar());
  76             frame.add(new JRadioButton("JRadioButton"));
  77             frame.add(new JScrollBar());
  78             frame.add(new JScrollPane());


< prev index next >