に分割されたパネルでペイントする方法最近、私はpaintComponent関数が関数内で呼び出されていないことを問題に会った、と私は分割区画機能を使用する場合、それは無効になりますことを発見しましたペイント機能、およびエラーを与える:は、Javaのスイング
cannot add to layout: unknown constraint: null
私は以下、ペイント機能は、正しい道に追加されないかもしれないと思うが(一部は)私のコードです:
クラス:テスト
public class Test extends JFrame{
public Test() throws IOException{
//JFrame jf = new JFrame("my frame");
this.add(new NewPanel(this));
this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
this.setBounds(300,200,1050,600);
this.setVisible (true);
}
public static void main (String[] args) throws IOException{
Test test = new Test();
test.setTitle("Hello");
//frame.pack();
}
}
クラス:NEWPANEL
public class NewPanel extends JPanel{
public NewPanel(JFrame frame) throws IOException{
JTabbedPane jTabbedpane = new JTabbedPane();
JSplitPane splitPane = new JSplitPane();
JPanel p1 = new JPanel();
p1.setLayout(null);
p2.setLayout(new FlowLayout());
splitPane.setOneTouchExpandable(true);
splitPane.setContinuousLayout(true);
//splitPane.setPreferredSize(new Dimension (250,500));
splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
splitPane.setLeftComponent(p1);
splitPane.setRightComponent (p2);
splitPane.setDividerSize(3);
splitPane.setDividerLocation(250); //balance two panels width
jTabbedpane.addTab("ABC",p2);
jTabbedpane.addTab("AB",p3);
jTabbedpane.addTab("AC",p4);
jTabbedpane.addTab("BC",p5);
frame.setContentPane(splitPane);
frame.add(jTabbedpane);
}
}
public void paintComponent(Graphics g){
super.paint(g);
g.setColor(Color.BLUE);
g.drawLine(303, 90, 303, 200);
g.drawLine(583, 90, 583, 200);
g.drawLine(863, 90, 863, 200);
}
}
私はframe.add(jTabbedpane)
コメントすると、ラインが、パネルに描かれたことができるがそれは1枚のパネルでのみ利用可能ですが、私は「私はドン、別の分割パネルにそれを描くことができません理由を知りません。そしてframe.add(jTabbedpane)
のコメントを外すと、上記のエラーがポップアップします。