Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Swing / AWT / SWT
JOptionPane Input Dialog
Arthur Buliva
Ranch Hand
Posts: 101
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi friends,
How does one set a value of a JOptionPane's inputDialog to have a preset
String
in the input?
This code:
String newWord = JOptionPane.showInputDialog(null, "Please enter the New Word", "Test Application", JOptionPane.PLAIN_MESSAGE);
Displays the dialog correctly, but I would like the field to bear the old
word
as a preset string.
Rob Spoor
Sheriff
Posts: 22862
132
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Quite odd. There is one method that has the initial value, but only if you don't want to specify the title and icon.
You could use plain old showConfirmDialog though:
JTextField field = new JTextField(30); field.setText("default value"); Object[] message = {"Please enter the New Word", field}; int answer = JOptionPane.showConfirmDialog(null, message, "Test Application", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (answer == JOptionPane.OK_OPTION) { String word = field.getText(); }
Moving to Swing / AWT.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Arthur Buliva
Ranch Hand
Posts: 101
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Maybe I didn't communicate appropriately. let me use diagrams then.
See the attached figure. When the input dialog is initialised, it displays as in fig 1. My wish is to have it display as fig 2 UPON INITIALIZATION.
Images.png
Descriptive Image
Michael Dunn
Ranch Hand
Posts: 4632
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
> Maybe I didn't communicate appropriately.
not really, there are 6 x JOptionPane.showInputDialog(...)'s
only 3 have a parameter for 'initialSelectionValue'
pick the one best suited, or
use Rob's suggestion, or
roll-your-own showInputDialog via createDialog and setWantsInput(true)
Arthur Buliva
Ranch Hand
Posts: 101
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks! This is what I wanted:
String newWord = JOptionPane.showInputDialog(null, "Please enter the New Word", "My Old Word");
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Selecting some entries in selectManyListbox
Parent and child window cncept in java swing
Getting a CheckBoxGroup to render with some items already selected... how?
how to set selected path to struts html:file when it redirects to same page
[Confusion] A Java Question
More...