JOptionPane layout customization

1

I have the following structure of my JOptionPane, with horizontal typing :

Howtoleavetypingfieldsvertically?

Hereistheclasscodebelow:

importjavax.swing.*;publicclassJOptionPaneMultiInput{publicstaticvoidmain(String[]args){JTextFieldfieldNome=newJTextField(5);JTextFieldfieldTelefone=newJTextField(5);JTextFieldfieldEmail=newJTextField(5);JPanelmyPanel=newJPanel();myPanel.add(newJLabel("Digite Nome:"));
      myPanel.add(fieldNome);
      myPanel.add(Box.createHorizontalStrut(15)); // a spacer
      myPanel.add(new JLabel("Digite Telefone:"));
      myPanel.add(fieldTelefone);
      myPanel.add(Box.createHorizontalStrut(15)); // a spacer
      myPanel.add(new JLabel("Digite Email:"));
      myPanel.add(fieldEmail);

      int result = JOptionPane.showConfirmDialog(null, myPanel, 
               "Entrada de valores", JOptionPane.OK_CANCEL_OPTION);
      if (result == JOptionPane.OK_OPTION) {
         System.out.println("Nome value: " + fieldNome.getText());
         System.out.println("Telefone value: " + fieldTelefone.getText());
         System.out.println("Email value: " + fieldEmail.getText());
      }

   }
}
    
asked by anonymous 09.10.2014 / 02:03

1 answer

1

With the help of @Wakim with the use of GridLayout I was able to, as a result of the figure below:

Code added below, resulting in fields in upright position:

 GridLayout experimentLayout = new GridLayout(0,1);
 myPanel.setLayout(experimentLayout);
    
09.10.2014 / 03:18