2

Where is this method from? I've tried looking for it and i cant find it. The only example i've seen it used in was where JPanel is extended and it is called in the constructor. The problem is i do not want to extend JPanel so how do i go about creating an object(my question is what class) so that i can access this method? I don't know where JPanel inherited this method from.

JComponent panel1 = makeTextPanel("Panel");
tabs.addTab("Display", panel1);

http://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html

user2644819
  • 1,787
  • 7
  • 28
  • 41

1 Answers1

4

It is from here: TabbedPaneDemo.java which can be found under the heading: "Code for Tabbed Panes" on that page.

protected Component makeTextPanel(String text) {
    JPanel panel = new JPanel(false);
    JLabel filler = new JLabel(text);
    filler.setHorizontalAlignment(JLabel.CENTER);
    panel.setLayout(new GridLayout(1, 1));
    panel.add(filler);
    return panel;
}

You don't have to extend anything. You can make it static.

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132