Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

swing - when should I use JFrame.add(component) and JFrame.getContentPane().add(component) in java

Is there a difference between them and are there any conditions in which one should be used instead of the other?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Both calls are the same. In Java 5, they changed jframe.add to forward calls to the content pane.

From the Java 5 release notes:

Lastly, after seven years, we've made jFrame.add equivalent to jFrame.getContentPane().add().

Also, see the javadocs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...