开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜