无法将JTextField或JList添加到面板-Java

时间:2018-06-21 16:26:06

标签: java panel textfield

当我将Jtextfield(或Jlist)添加到面板时,一切都消失了。但是,如果我使用此按钮和复选框仍然有效。我下面有2张详细图片。

这是我的主面板:

private JPanel mainPanel() {
    JPanel panel = new JPanel();

    panel.setBorder(new EmptyBorder(5, 5, 5, 5));
    panel.setLayout(new BorderLayout(0, 0));

    panel.add(namePanel(), BorderLayout.NORTH);
    panel.add(optionPanel(), BorderLayout.WEST);
    panel.add(infoPanel(), BorderLayout.CENTER);
    //panel.add(closePanel(), BorderLayout.SOUTH);


    return panel;

}

错误文本字段位于infoPanel中:

private JPanel infoPanel() {
    JPanel panel = new JPanel();
    panel.setBorder(new TitledBorder(new LineBorder(new Color(250, 0, 0)), "Nhập thông tin:", TitledBorder.LEADING, TitledBorder.TOP, null, null));


    JButton btnNhap = new JButton("Nhập");
    panel.add(btnNhap);

    //JTextField txfNhap = new JTextField();
    //panel.add(txfNhap);

    JCheckBox cbxAm = new JCheckBox("Cho nhập số âm");
    panel.add(cbxAm);



    return panel;
}

详细图片:

-您可以在图像中看到Jtextfield的代码

(Image1)Error when add textfield

(Image2)when disable the text field.. Everything still working

0 个答案:

没有答案