开发者

Does getContentPane().add() mean the same as add()

开发者 https://www.devze.com 2023-03-04 18:41 出处:网络
Does 开发者_高级运维getContentPane().add() mean the same as add() ? public class TestFrame extends JFrame{

Does 开发者_高级运维getContentPane().add() mean the same as add() ?

public class TestFrame extends JFrame{
    public TestFrame() {
        JLabel label = new JLabel("jo");
        getContentPane().add(label);
        add(label);
    }
}


Does getContentPane().add() mean the same as add() ?

Yes, since 1.5+.


Mostly. To make things "easier", addImpl was changed to forward to the content pane, but in uncommon corner cases it doesn't (for instance, the content pane needs to be added somehow).

This method is overridden to conditionally forward calls to the contentPane.


Yes, because if you notice they both are from

Class Container
java.lang.Object
  java.awt.Component
      java.awt.Container
add()

JLabel extends container and getContentPane() returns container.

0

精彩评论

暂无评论...
验证码 换一张
取 消