How to make the cursor in the JTextField area multiple rows in FlowLayout?

enter image description here

How can I start the cursor in the upper left corner of a JTextField? The text just stays centered when I adjust the height with .setPreferredSize (). Here is the code for the fields and buttons.

public class GUIWindow extends JFrame{

    private JTextField inputBox = new JTextField(20);
    private JTextField outputBox = new JTextField(20);
    private JButton encodeButton = new JButton("Encode");
    private JButton decodeButton = new JButton("Decode");

    public GUIWindow(){
        JPanel mainPanel = new JPanel(new FlowLayout());
        outputBox.setPreferredSize(new Dimension(80, 80));
        inputBox.setPreferredSize(new Dimension(80, 80));
        outputBox.setEditable(false);
        mainPanel.add(inputBox);
        mainPanel.add(encodeButton);
        mainPanel.add(decodeButton);
        mainPanel.add(outputBox);
        Container container = getContentPane();
        container.add(mainPanel);
    }
}
+3
source share
1 answer

If you are looking for multi-line control, you should use JTextArea instead of JTextField.

+3
source

All Articles