【问题标题】:How to make the cursor in a JTextField span multiple rows in FlowLayout?如何使 JTextField 中的光标跨越 FlowLayout 中的多行?
【发布时间】:2011-05-16 21:26:14
【问题描述】:

如何使光标从 JTextField 的左上角开始?当我使用 .setPreferredSize() 调整高度时,文本保持居中。这是字段和按钮的代码。

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);
    }
}

【问题讨论】:

    标签: java swing jtextfield flowlayout


    【解决方案1】:

    如果您正在寻找多行控件,那么您应该使用 JTextArea 而不是 JTextField。

    【讨论】:

    • 正是我所缺少的。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-24
    • 2012-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多