JOptionPane with multiple inputs on different lines

I would like to create JOptionPaneone that allows the user to select the IP address and port to connect. It should be structured as such,

IP Address: [text box here]

Port: [text box here]

Cancel OK

Labels should be left aligned, and text boxes should also be left aligned. I can't model the storyboard here, but basically the text fields should not be offset, even if there is a space between the labels and the text fields.

Each pair of labels and text fields should be on separate lines, and the Cancel buttons OK should be aligned to the right under the text fields.

Is there any way to do this in code?

+5
source share
2 answers

. , .

hqCeE.png

, , , , :

labels.add(new JLabel("User Name", SwingConstants.RIGHT));

:

labels.add(new JLabel("User Name"));

, GridLayout WEST CENTER BorderLayout.

, , MigLayout J2SE, BoxLayout GroupLayout.

GroupLayout , , CENTER ( , , 2 ). , , .

+10
+4

All Articles