Text wrap in JOptionPane?

A JOptionPane will use a JLabel to display text by default. A label will format HTML. Set the maximum width in CSS. JOptionPane.showMessageDialog( this, “<html><body><p style=”width: 200px;”>”+exp.getMessage()+”</p></body></html>”, “Error”, JOptionPane.ERROR_MESSAGE); More generally, see How to Use HTML in Swing Components, as well as this simple example of using HTML in JLabel.

JOptionPane to get password

Yes, it is possible using JOptionPane.showOptionDialog(). Something like this: JPanel panel = new JPanel(); JLabel label = new JLabel(“Enter a password:”); JPasswordField pass = new JPasswordField(10); panel.add(label); panel.add(pass); String[] options = new String[]{“OK”, “Cancel”}; int option = JOptionPane.showOptionDialog(null, panel, “The title”, JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]); if(option == 0) // pressing OK button { char[] … Read more

Multiple input in JOptionPane.showInputDialog

Yes. You know that you can put any Object into the Object parameter of most JOptionPane.showXXX methods, and often that Object happens to be a JPanel. In your situation, perhaps you could use a JPanel that has several JTextFields in it: import javax.swing.*; public class JOptionPaneMultiInput { public static void main(String[] args) { JTextField xField … Read more

How to present a simple alert message in java?

I’ll be the first to admit Java can be very verbose, but I don’t think this is unreasonable: JOptionPane.showMessageDialog(null, “My Goodness, this is so concise”); If you statically import javax.swing.JOptionPane.showMessageDialog using: import static javax.swing.JOptionPane.showMessageDialog; This further reduces to showMessageDialog(null, “This is even shorter”);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)