dimanche 30 novembre 2014

Why 'JRootPane' is-a 'JComponent' in javax.swing?


As per below code, I see that, setLayout() is being called on a JRootPane object instead of JFrame top level container in javx.swing world unlike java.awt, because it is told that swing's JFrame is light-weight container compared to AWT's Frame.



public class TestGetContentPane extends JFrame {
public TestGetContentPane() {
Container cp = this.getContentPane(); // cp points to 'JRootPane' object
cp.setLayout(new FlowLayout());
cp.add(new JLabel("Hello, world!"));
cp.add(new JButton("Button"));
......
}
.......
}


Any JComponent will be part of the layout set in Content-pane JRootPane which in-turn is a member JFrame or JDialog top-level containers. So, JRootPane looks like a container but not component.



/**
* @see #getRootPane
* @see #setRootPane
*/
protected JRootPane rootPane; //member of JFrame or JDialog


Interestingly, below code says that, JRootPane is-a JComponent.



public class JRootPane extends JComponent implements Accessible {}


My question is,


1) What exactly do they mean, when they say JFrame is light-weight container unlike AWT Frame?


2) Why JRootPane is-a JComponent? I feel, JRootPane should be along the class hierarchy where JFrame & JDialog sit under Container





Aucun commentaire:

Enregistrer un commentaire