• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JOptionPane with lable and textfield

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In JOptionPane, I want to show password label and its corresponding password textfiled in one line and then confirm password label and corresponding textfield in another line. Can anybody give me sample code for this ??

I am able to put the controllers in the JOptionPane one below the other. But not one after the other.


private ButtonGroup buttonGroup = new ButtonGroup();
private JRadioButton radioButton1 = new JRadioButton("Use default password");
private JRadioButton radioButton2 = new JRadioButton("I have changed the password");
private JLabel passwordLbl = new JLabel("Password:");
private JTextField passwordTF = new JTextField();

private Object[] pwdArray = {passwordLbl, passwordTF};

private String difficultyString = "<html>Log in to the database failed.<br>Please select any of the following options below.</br></html>";
private Object[] radioButtonArray = {difficultyString, radioButton1, radioButton2, pwdArray};

JOptionPane.showConfirmDialog(this,
radioButtonArray, "Level selection",
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE);

Please suggest me some way to achieve this.

Regards,
Satya
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by satya sahu:

JOptionPane.showConfirmDialog(this,
radioButtonArray, "Level selection",
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE);

Please suggest me some way to achieve this.



1) Create a JPanel instance.
2) Add all your components (radio buttons, labels, password fields etc) to it
3) Pass the panel to the JOptionPane instead of the radioButtonArray.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic