简体   繁体   中英

Assigning JButton to any location

I have added my button to my Container which can hold components , everything works fine however, the clearButton.setLocation() method below is not working. any ideas?

public JButton clearButton(){ // clearButton method
    JButton clearButton = new JButton("CLEAR"); // new button of type JButton
    clearButton.setPreferredSize(new Dimension(200,30)); // dimension of the button
    clearButton.setLocation(400,450);
    return clearButton; // return reference to the JButton object
}

You have to set a absolute layout to the JPanel where you are adding the button to. Then it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM