开发者

How to make the cursor in a JTextField span multiple rows in FlowLayout?

How to make the cursor in a JTextField span multiple rows in FlowLayout?

How can I make the cursor start at the top left of the 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()开发者_JAVA技巧;
        container.add(mainPanel);
    }
}


If you are looking for a multiline control then you should use a JTextArea instead of JTextField.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜