有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何将JTextField添加到带有JButton的Jpanel中

我添加了JtextField行,但在输出中只显示按钮。我错过了什么,请用java代码写下你的答案。谢谢

 public JPanel createContentPane (){
JButton Button1
buttonPanel = new JPanel();
buttonPanel.setLayout(null);
buttonPanel.setLocation(10, 50);
buttonPanel.setSize(1370, 770);
totalGUI.add(buttonPanel);

    Button1 = new JButton("Button 1");
    Button1.setLocation(0, 0);
    Button1.setSize(120, 30);
    Button1.addActionListener(this);
    buttonPanel.add(Button1);

  JLabel l;
  l= new JLabel;
  JTextField a = new JTextField();
    a.setVisible(true);
    a.setLocation(1000,200);
    l.add(a);
}

这是主要的方法和createAndShowGUI

private  void createAndShowGUI() {


        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame frame = new JFrame("[=] JButton Scores! [=]");



        //Create and set up the content pane.
        ButtonExample_Extended demo = new ButtonExample_Extended();
        frame.setContentPane(demo.createContentPane());

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(1370, 770);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new ButtonExample_Extended().createAndShowGUI();
            }
        });
    }

共 (0) 个答案