あなたがこれを行うことができますカップルの方法で、JPanel
を拡張したり、あなたのJTabbedPane
あなたの作成に続いてソリューション
に
public class MyCustomPanel extends JPanel {
// implement your custom behavior in here
}
をベースにJPanel
継承が含まれている別のクラスを作成するのいずれかがあります。
これは機能しますが、JPanel
を延長すると長期的に頭痛を引き起こす可能性があります。ソリューションその後、
public class MyCustomPanel {
private JPanel myPanel = new JPanel();
public MyCustomPanel() {
// add your customizations to myPanel
}
public JPanel getPanel() {
return myPanel;
}
}
とをベースに
作曲、あなたのJTabbedPane
private void init() {
JTabbedPane jtp = new JTabbedPane();
MyCustomPanel mp = new MyCustomPanel();
jtp.add(mp.getPanel());
}
を作成:composition over inheritanceを好むもう一つのapproacheは、このようになります。