• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JOptionPane with lable and textfield

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • 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: 11445
18
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!