首页 > 解决方案 > SetLocation(int , int) 不工作

问题描述

为什么setLocation(int, int)无法设置按钮的位置。我有一个ABC添加两个的类,JButton然后JPanel将此面板添加到,JFrame但是在设置 JButton 的位置时,按钮是并排添加的,但不是在所需的位置。我认为这是因为Flowloyout.

ABC(){
    jframe = new JFrame();
    jframe.setSize(600, 600);
    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jframe.setVisible(true);
    start = true;
    jbutton1 = new JButton("Button1");
    jbutton2 = new JButton("Button2");


    jbutton1.setLocation(200, 500);
    jbutton2.setLocation(300, 550);

    // first window of the application
    JPanel jp = new JPanel();
    jp.add(jbutton1);
    jp.add(jbutton2);

    jframe.add(jp);
    }

标签: javaswing

解决方案


推荐阅读