List of usage examples for org.eclipse.swt.widgets Label isDisposed
public boolean isDisposed()
true
if the widget has been disposed, and false
otherwise. From source file:TimeStopWhenButtonPressing.java
public static void main(String[] args) { final Display display = new Display(); final Color red = display.getSystemColor(SWT.COLOR_RED); final Color blue = display.getSystemColor(SWT.COLOR_BLUE); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Button button = new Button(shell, SWT.PUSH); button.setText("Stop Timer"); final Label label = new Label(shell, SWT.BORDER); label.setBackground(red);// ww w . j a v a2 s.c o m final int time = 500; final Runnable timer = new Runnable() { public void run() { if (label.isDisposed()) return; Color color = label.getBackground().equals(red) ? blue : red; label.setBackground(color); display.timerExec(time, this); } }; display.timerExec(time, timer); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { display.timerExec(-1, timer); } }); button.pack(); label.setLayoutData(new RowData(button.getSize())); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet68.java
public static void main(String[] args) { final Display display = new Display(); final Color red = display.getSystemColor(SWT.COLOR_RED); final Color blue = display.getSystemColor(SWT.COLOR_BLUE); Shell shell = new Shell(display); shell.setText("Snippet 68"); shell.setLayout(new RowLayout()); Button button = new Button(shell, SWT.PUSH); button.setText("Stop Timer"); final Label label = new Label(shell, SWT.BORDER); label.setBackground(red);/*ww w . j a v a2 s . com*/ final int time = 500; final Runnable timer = new Runnable() { @Override public void run() { if (label.isDisposed()) return; Color color = label.getBackground().equals(red) ? blue : red; label.setBackground(color); display.timerExec(time, this); } }; display.timerExec(time, timer); button.addListener(SWT.Selection, event -> display.timerExec(-1, timer)); button.pack(); label.setLayoutData(new RowData(button.getSize())); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }