Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
626 views
in Technique[技术] by (71.8m points)

swing - Setting the size of a ContentPane (inside of a JFrame)

I want to set the size of a JFrame such that the contentPane is the desired size. JFrame.setSize() doesn't take the window decorations into account, so the contentPane is slightly too small. The size of the window decorations are platform and theme specific, so it's bad news to try to manually account for them.

JFrame.getContentPane().setSize() fails because it's managed.

Ideas?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In Java 5 and later this is the easiest method:

JFrame frame = new JFrame("Content Pane Size Example");
frame.getContentPane().setPreferredSize(new Dimension(400, 300));
frame.pack();
frame.setVisible(true);

As always the above should be executed in the EDT.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...