JOptionPane with two labels
-
30-09-2019 - |
문제
I would like to create in Java a JOptionPane which should contain two different labels, Is it possible? If so, how to do it?
해결책
JOptionPane do not consist of labels. It's a built in component for showing a standard pop up box with various buttons. You might wish to implement your own JFrame, that looks identical to a normal JOptionPane, with however way/many text included.
다른 팁
Your message parameter can be an array of JComponent objects which will be drawn in sequence. An example would be:
JLabel[] arr = {new JLabel("Paragraph 1"), new JLabel("Paragraph 2")};
JOptionPane.showMessageDialog(null, arr);
You can a \n
in the string you want to print, so for instance "Hello\nWorld" would look like
Hello
World
which is similar to having to labels.
There are other escape characters, you can take a look at them here
제휴하지 않습니다 StackOverflow