List of usage examples for javax.swing SwingUtilities isEventDispatchThread
public static boolean isEventDispatchThread()
From source file:Main.java
public static int getX(final Component component) { if (component != null) { if (SwingUtilities.isEventDispatchThread()) { return component.getX(); } else {/* w w w .j a v a 2s .c o m*/ final int[] x = new int[1]; try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { x[0] = component.getX(); } }); } catch (InterruptedException | InvocationTargetException e) { } return x[0]; } } else { return 0; } }
From source file:Main.java
/** * Invokes {@code run} immediately if this is the * EDT; otherwise, the {@code Runnable} is invoked * on the EDT using {@code invokeLater}. *///from w ww . j a v a 2s . c o m public static void invokeNowOrLater(Runnable run) { if (SwingUtilities.isEventDispatchThread()) { run.run(); } else { SwingUtilities.invokeLater(run); } }
From source file:Main.java
public static int getWidth(final Component component) { if (component != null) { if (SwingUtilities.isEventDispatchThread()) { return component.getWidth(); } else {/*from w w w.j a v a 2 s . c o m*/ final int[] width = new int[1]; try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { width[0] = component.getWidth(); } }); } catch (InterruptedException | InvocationTargetException e) { } return width[0]; } } else { return 0; } }
From source file:Main.java
public static int getHeight(final Component component) { if (component != null) { if (SwingUtilities.isEventDispatchThread()) { return component.getHeight(); } else {/* ww w . j av a 2 s .c o m*/ final int[] height = new int[1]; try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { height[0] = component.getHeight(); } }); } catch (InterruptedException | InvocationTargetException e) { } return height[0]; } } else { return 0; } }
From source file:Main.java
public static boolean isVisible(final Component component) { if (component != null) { if (SwingUtilities.isEventDispatchThread()) { return component.isVisible(); } else {/* w ww. j a v a 2 s .c o m*/ final boolean[] isVisible = new boolean[1]; try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { isVisible[0] = component.isVisible(); } }); } catch (InterruptedException | InvocationTargetException e) { } return isVisible[0]; } } else { return false; } }
From source file:Main.java
private static void doSetSize(final Component component, final int width, final int height) { if (component != null && width >= 0 && height >= 0) { if (SwingUtilities.isEventDispatchThread()) { doSetSizeInEDT(component, width, height); } else {/* w w w . j a v a 2 s. c o m*/ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { doSetSizeInEDT(component, width, height); } }); } } }
From source file:Main.java
public static String getText(final AbstractButton abstractButton) { if (abstractButton != null) { if (SwingUtilities.isEventDispatchThread()) { return abstractButton.getText(); } else {//from w w w . j av a 2s . com final String[] text = { "" }; try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { text[0] = abstractButton.getText(); } }); } catch (InterruptedException | InvocationTargetException e) { } if (text[0] == null) { text[0] = ""; } return text[0]; } } else { return ""; } }
From source file:Main.java
public static void add(final Component component, final Container container) { if (component != null && container != null) { if (SwingUtilities.isEventDispatchThread()) { container.add(component);//w w w . j a va2 s. c o m } else { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { container.add(component); } }); } catch (InterruptedException | InvocationTargetException e) { } } } }
From source file:Main.java
private static void doSetResizable(final Frame frame, final boolean isResizable) { if (frame != null) { if (SwingUtilities.isEventDispatchThread()) { doSetResizableInEDT(frame, isResizable); } else {/* w w w .j a v a2 s . com*/ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { doSetResizableInEDT(frame, isResizable); } }); } } }
From source file:Main.java
public static Object getClientProperty(final JComponent jComponent, final Object key, final Object value) { if (jComponent != null && key != null) { if (SwingUtilities.isEventDispatchThread()) { Object clientProperty = jComponent.getClientProperty(key); if (clientProperty == null) { clientProperty = value;//w w w .ja v a 2 s.c om } return clientProperty; } else { final Object[] clientProperty = new Object[] { value }; try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { clientProperty[0] = jComponent.getClientProperty(key); } }); } catch (InterruptedException | InvocationTargetException e) { } if (clientProperty[0] == null) { clientProperty[0] = value; } return clientProperty[0]; } } else { return value; } }