Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
    }
}
like image 501
why Avatar asked May 07 '11 13:05

why


2 Answers

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

Yes, since 1.5+.

like image 69
Andrew Thompson Avatar answered Sep 19 '22 05:09

Andrew Thompson


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.

like image 41
Tom Hawtin - tackline Avatar answered Sep 19 '22 05:09

Tom Hawtin - tackline