简体   繁体   中英

Java multiple button size issue

I'm making a simple hobby piece that simply contains two buttons. When I try to set the size only one button, the work button, is set. This is true even if I comment out the play button code.

Here is the button creation code:

Container content = frame.getContentPane();
JButton workBtn = new JButton("Work");
JButton playBtn = new JButton("Play");
workBtn.setSize(100, 100);
playBtn.setSize(100, 100);
workBtn.setVisible(true);
playBtn.setVisible(true);
content.add(workBtn);
content.add(playBtn);

I'm guessing it's something simple but I just can't see what or find that out.

JFrame contentPanes use BorderLayout by default. Read up on the layout managers to learn how to best use them to your advantage. You can find the link here .

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