• 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:

JOptionPane Input Dialog

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! This is what I wanted:

reply
    Bookmark Topic Watch Topic
  • New Topic