This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane Input Dialog

 
Arthur Buliva
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,

How does one set a value of a JOptionPane's inputDialog to have a preset String in the input?

This code:



Displays the dialog correctly, but I would like the field to bear the old word as a preset string.
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
Moving to Swing / AWT.
 
Arthur Buliva
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
[Thumbnail for Images.png]
Descriptive Image
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! This is what I wanted:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!