InputDialog in vertical

0

My problem is that I want to create a graphical interface with vertical insert fields, but I can only create it horizontally.

Code:

JTextField mapField = new JTextField(5);
JTextField tamField = new JTextField(5);
JTextField wordField = new JTextField(5);
JTextField politicaField = new JTextField(5);
JTextField numViasField = new JTextField(5);
JPanel myPanel = new JPanel();
myPanel.add(new JLabel("Mapeamento:"));
myPanel.add(mapField);
myPanel.add(Box.createVerticalStrut(15)); // a spacer
myPanel.add(new JLabel("Tamanho da Cache:"));
myPanel.add(tamField);
myPanel.add(Box.createVerticalStrut(15)); // a spacer
myPanel.add(new JLabel("Wors por bloco:"));
myPanel.add(wordField);
myPanel.add(Box.createVerticalStrut(15)); // a spacer
myPanel.add(new JLabel("Politica de substituição:"));
myPanel.add(politicaField);
myPanel.add(Box.createVerticalStrut(15)); // a spacer
myPanel.add(new JLabel("Numero de vias:"));
myPanel.add(numViasField);
    
asked by anonymous 21.11.2014 / 13:29

1 answer

3

Your problem is that you are not using any of the layout :

frame.setLayout(new GridLayout(x, y));
//x - é o numero de linhas
//y - é o numero de colunas

Example:

import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

public class GridLayoutTest {

  public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("GridLayout Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new GridLayout(10, 1));
    frame.add(new JButton("Button 1"));
    frame.add(new JButton("Button 2"));
    frame.add(new JButton("Button 3"));
    frame.add(new JButton("Button 4"));
    frame.add(new JButton("Button 5"));
    frame.add(new JButton("Button 6"));
    frame.add(new JButton("Button 7"));
    frame.add(new JButton("Button 8"));
    frame.pack();
    frame.setVisible(true);
  }
}

Font

To help you better understand the layout :

link

    
21.11.2014 / 14:21