This is the old documentation of lombok-pg. The new version can be found in the wiki of the github repository. Take me to the new Version then!

@SwingInvokeLater/@SwingInvokeAndWait

Overview

Detailed Description

With Lombok

01 import lombok.SwingInvokeLater;
02 import lombok.SwingInvokeLater;
03 
04 import javax.swing.JFrame;
05 
06 class SwingInvokeLaterExample {
07 
08   @SwingInvokeLater
09   void createUI() {
10     JFrame frame = new JFrame()
11     frame.setTitle("Application");
12     frame.setVisible(true);
13   }
14 }
15 
16 class SwingInvokeAndWaitExample {
17 
18   @SwingInvokeAndWait
19   void createUI() {
20     JFrame frame = new JFrame()
21     frame.setTitle("Application");
22     frame.setVisible(true);
23   }
24 }

Vanilla Java

01 import javax.swing.JFrame;
02 
03 class SwingInvokeLaterExample {
04 
05   void createUI() {
06     final java.lang.Runnable $createUIRunnable = new java.lang.Runnable(){
07       @java.lang.Override
08       public void run() {
09         JFrame frame = new JFrame()
10         frame.setTitle("Application");
11         frame.setVisible(true);
12       }
13     };
14     if (java.awt.EventQueue.isDispatchThread()) {
15       $createUIRunnable.run();
16     else {
17       java.awt.EventQueue.invokeLater($createUIRunnable);
18     }
19   }
20 }
21 
22 class SwingInvokeAndWaitExample {
23 
24   void createUI() {
25     final java.lang.Runnable $createUIRunnable = new java.lang.Runnable(){
26       @java.lang.Override
27       public void run() {
28         JFrame frame = new JFrame()
29         frame.setTitle("Application");
30         frame.setVisible(true);
31       }
32     };
33     if (java.awt.EventQueue.isDispatchThread()) {
34       $createUIRunnable.run();
35     else {
36       try {
37         java.awt.EventQueue.invokeAndWait($createUIRunnable);
38       catch (final java.lang.InterruptedException $ex1) {
39       catch (final java.lang.reflect.InvocationTargetException $ex2) {
40         if ($ex2.getCause() != nullthrow new java.lang.RuntimeException($ex2.getCause());
41       }
42     }
43   }
44 }

Small print

Smallprint