Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to applty setMneomonic in Confirm Dialog of JOption Pane

 
aminur rashid
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi I am using

i know how to set the hot keys( setMnemonic(char)) in the JButton but i dont know how to use it in JOptionPane
Also i want to take password input from JOptionPane.showInputDailog
how i can call setEchoCahr('*');
for input dialog
thanks
Regards
Md Aminur Rashid
Pune
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Aminur,
try:
JPanel panel = new JPanel();
JLabel label = new JLabel("type your password:");
JPasswordField passField = new JPasswordField();
panel.setLayout(new BorderLayout());
panel.add(label, BorderLayout.NORTH);
panel.add(passField, BorderLayout.SOUTH);
JOptionPane.showConfirmDialog(null, panel, "Password request", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
char[] password = passField.getPassword();
hava fun,
chantal
 
aminur rashid
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks tell me also how to call setMnemonic(char c);
for the Yes_No option of JOptionPane.showConfirmDialog
Originally posted by Chantal Ackermann:
hi Aminur,
try:
JPanel panel = new JPanel();
JLabel label = new JLabel("type your password:");
JPasswordField passField = new JPasswordField();
panel.setLayout(new BorderLayout());
panel.add(label, BorderLayout.NORTH);
panel.add(passField, BorderLayout.SOUTH);
JOptionPane.showConfirmDialog(null, panel, "Password request", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
char[] password = passField.getPassword();
hava fun,
chantal

 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Aminur,
have you tried if this mnemonic isn't already set by default? I mean, write a small test application and see if the button is marked as and reacts like a mnemonic.
if not: use
JOptionPane.showOptionDialog()

with the same parameter set as above, but additionaly specifying Object[] options (and what else will be necessary).
API: JOptionPane.showOptionDialog()
Parameter options - an array of objects indicating the possible choices the user can make; if the objects are components, they are rendered properly.
that means you can provide buttons with a mnemonic specification as argument.
chantal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic