Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-02-2008, 09:53 PM
Moderator
 
Join Date: Nov 2007
Posts: 1,659
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Creating a Number Input Dialog in SWT
Code:
import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Dialog; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class NumberInputDialog extends Dialog { Double value; /** * @param parent */ public NumberInputDialog(Shell parent) { super(parent); } /** * @param parent * @param style */ public NumberInputDialog(Shell parent, int style) { super(parent, style); } /** * Makes the dialog visible. * * @return */ public Double open() { Shell parent = getParent(); final Shell shell = new Shell(parent, SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL); shell.setText("NumberInputDialog"); shell.setLayout(new GridLayout(2, true)); Label label = new Label(shell, SWT.NULL); label.setText("Please enter a valid number:"); final Text text = new Text(shell, SWT.SINGLE | SWT.BORDER); final Button buttonOK = new Button(shell, SWT.PUSH); buttonOK.setText("Ok"); buttonOK.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); Button buttonCancel = new Button(shell, SWT.PUSH); buttonCancel.setText("Cancel"); text.addListener(SWT.Modify, new Listener() { public void handleEvent(Event event) { try { value = new Double(text.getText()); buttonOK.setEnabled(true); } catch (Exception e) { buttonOK.setEnabled(false); } } }); buttonOK.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { shell.dispose(); } }); buttonCancel.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { value = null; shell.dispose(); } }); shell.addListener(SWT.Traverse, new Listener() { public void handleEvent(Event event) { if(event.detail == SWT.TRAVERSE_ESCAPE) event.doit = false; } }); text.setText(""); shell.pack(); shell.open(); Display display = parent.getDisplay(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } return value; } public static void main(String[] args) { Shell shell = new Shell(); NumberInputDialog dialog = new NumberInputDialog(shell); System.out.println(dialog.open()); } }
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums! (closes on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Input Verification Dialog Demo Java Tip javax.swing 0 06-26-2008 09:43 PM
Creating a dialog to input user/password prfalco New To Java 4 02-18-2008 09:03 AM
JOptionPane - input dialog Java Tip Java Tips 0 12-17-2007 11:09 AM
how to take input and verify input in Java programs bilal_ali_java Advanced Java 0 07-21-2007 10:46 AM
Multiple Line Input Dialog Box johnt AWT / Swing 2 05-31-2007 11:30 PM


All times are GMT +3. The time now is 03:33 AM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org