Wenn der Benutzer das Passwort eingibt und auf die Schaltfläche OK klickt, wird das Passwort verschlüsselt und in gespeichert. Und das funktioniert gut. Aber ich möchte ein benutzerdefiniertes Logo in den showConfirmDialog
und showMessageDialog
Popup hinzufügen. Ich habe versucht, mit dem folgenden Code, aber das benutzerdefinierte Bild (Logo) ist die Anzeige nicht in der Nachricht PopupJava - Benutzerdefiniertes Bild in JoptionPane.ShowConfirmDialog funktioniert nicht
public static void main(String[] args) {
Box box = Box.createHorizontalBox();
JLabel label = new JLabel("Enter your password : ");
box.add(label);
JPasswordField passwordField = new JPasswordField(24);
box.add(passwordField);
final ImageIcon icon = new ImageIcon("C:\\Users\\Test\\Internet.png");
int button = JOptionPane.showConfirmDialog(null, box, "Enter your password", JOptionPane.OK_CANCEL_OPTION, JOptionPane.NO_OPTION, icon);
if (button == JOptionPane.OK_OPTION) {
String password = new String(passwordField.getPassword());
String encryptedPassword;
if (password != null && !password.equals("")) {
byte[] bytesEncoded = Base64.encodeBase64(password.getBytes());
JTextArea richTextField = new JTextArea(10, 10);
encryptedPassword = new String(bytesEncoded);
richTextField.setText(encryptedPassword);
richTextField.setOpaque(false);
richTextField.setEditable(false);
JOptionPane.showMessageDialog(null, richTextField);
} else {
JOptionPane.showMessageDialog(null,
"Password cannot be null. Please enter password to encrypt.");
}
}
}<br>
ich vorbei ImageIcon
Gegenstand in die JoptionPane.showConfirmDialog
als Argument. Aber wenn ich das ausführe, sehe ich kein Bild im Popup angezeigt. Ich bin mir nicht sicher, was ich hier falsch mache.
Hinweis: Ich brauche ein benutzerdefiniertes Bild, das in beiden Popups angezeigt werden soll. showConfirmDialog
und showMessageDialog
Jede Hilfe
Es ist jetzt gut zu arbeiten, nachdem das Ändern der Bildgröße. Ich habe diese Zeilen hinzugefügt ImageIcon icon = new ImageIcon (relativePath); \t Image image = icon.getImage(); \t Image newimg = image.getScaledInstance (140, 140, java.awt.Image.SCALE_SMOOTH); \t Symbol = neuer ImageIcon (newimg); – Aishu
Das ist großartig Aishu. –