-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
1.4.0, 1.4.1
-
Fix Understood
-
x86
-
windows_2000, windows_xp
Name: jk109818 Date: 07/22/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION : all operating systems
A DESCRIPTION OF THE PROBLEM :
JOptionPane has some static convenience methods for showing
messages and requesting input. But there is NO (simple)
possibility to enter password text.
I had to write a huge subclass of JOptionPane - about 1500
lines of copy and paste (because of the many static &
private methods/variables) for adding just a few lines (see
below)
See the source-code for an implementation of this feature
EXPECTED VERSUS ACTUAL BEHAVIOR :
An OptionPane that has the possibility to display a
password field
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Add this to JOptionPane and it should work (at least with one password field)
public static char[] showPasswordDialog(Object message)
throws HeadlessException {
return showPasswordDialog(null, message);
}
public static char[] showPasswordDialog(Object message, Object
initialSelectionValue) {
return showPasswordDialog(null, message, initialSelectionValue);
}
public static char[] showPasswordDialog(Component parentComponent, Object
message) throws HeadlessException {
return showPasswordDialog(parentComponent, message, UIManager.getString
("OptionPane.passwordDialogTitle"), QUESTION_MESSAGE);
//@@@ ToDo: set title with UIManager.put
("OptionPane.passwordDialogTitle", "<Title>")
}
public static char[] showPasswordDialog(Component parentComponent, Object
message,
Object initialSelectionValue) {
return (char[])showPasswordDialog(parentComponent, message,
UIManager.getString("OptionPane.passwordDialogTitle"), QUESTION_MESSAGE, null,
null, initialSelectionValue);
}
public static char[] showPasswordDialog(Component parentComponent, Object
message, String title, int messageType) throws HeadlessException {
return (char[])showPasswordDialog(parentComponent, message, title,
messageType, null, null, null);
}
public static Object showPasswordDialog(Component parentComponent, Object
message, String title, int messageType, Icon icon, Object[] selectionValues,
Object initialSelectionValue) throws HeadlessException {
JPasswordField passwordField;
Object[] array;
OptionPane pane;
passwordField = new JPasswordField(10);
passwordField.setEchoChar('*');
array = new Object[]{message, passwordField};
pane = new OptionPane(array, messageType, OK_CANCEL_OPTION, icon, null,
null);
pane.setWantsInput(false);
pane.setSelectionValues(selectionValues);
pane.setInitialSelectionValue(initialSelectionValue);
pane.setComponentOrientation(((parentComponent == null) ?
getRootFrame() : parentComponent).getComponentOrientation());
int style = styleFromMessageType(messageType);
JDialog dialog = pane.createDialog(parentComponent, title, style);
pane.selectInitialValue();
dialog.show();
dialog.dispose();
Object value = passwordField.getPassword();
return value;
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Write a JDialog or a subclass of JOptionPane
(Review ID: 159608)
======================================================================