Results 1 to 3 of 3
Thread: Problem creating dialog box
- 08-13-2010, 05:19 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 24
- Rep Power
- 0
Problem creating dialog box
I'm creating a word processor similar to Microsoft Word (but much simpler). I'm having a problem with a dialog box.
When a user presses the 'new document' button, it prompts the user to enter the file name, and when the user does so, he presses ok, and the file name is stored in a variable. That works out fine, the problem is when the user presses cancel! I could think of no way to manipluate what happens when the user presses cancel, (the default action is that the file name is set as null, rather than just leaving it as it was before) so I added some code myself by identifying the length of the string - basically, if the length of the string is 0, then cancel was pressed because there was no input. However, I am getting an error. This is the code:
Java Code:private void newDocument() { String tempFileName = JOptionPane.showInputDialog(null, "Please enter file name", "Please enter file name", JOptionPane.INFORMATION_MESSAGE); if (tempFileName.length() == 0) { tempFileName = ""; } else { fileName = tempFileName; textArea.setText(null); } textArea.setEditable(true); textArea.setEnabled(true); enableButtons(); }
- 08-13-2010, 05:26 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
According to the API documentation the JOptionDialog returns null if the user canceled the dialog. Simply test for null being returned.
kind regards,
Jos
- 08-13-2010, 05:38 PM #3
Member
- Join Date
- Aug 2010
- Posts
- 24
- Rep Power
- 0
Similar Threads
-
Problem creating a new mobile app
By yasser1988 in forum NetBeansReplies: 0Last Post: 07-22-2010, 12:02 PM -
save dialog problem
By masa in forum AWT / SwingReplies: 2Last Post: 03-06-2009, 12:41 AM -
Problem in dialog
By Sarinam in forum New To JavaReplies: 5Last Post: 07-12-2008, 11:38 AM -
Creating a Number Input Dialog in SWT
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 07:53 PM -
Creating a dialog to input user/password
By prfalco in forum New To JavaReplies: 4Last Post: 02-18-2008, 07:03 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks