최근 자바 스윙에서 분할 패널에서 의 paintComponent 기능이 함수에서 호출되지 않는다는 문제를 칠하고, 나는 분할 구획 기능을 사용할 때, 그것은 비활성화됩니다 발견 기능을 페인트 및 오류 제공 :어떻게 내가 만난
클래스 : 테스트
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();
}
}
cannot add to layout: unknown constraint: null
내가 아래에 (부분적으로) 내 코드, 페인트 기능이 올바른 방법으로 추가 할 수 없습니다 생각
클래스 : 나는 frame.add(jTabbedpane)
언급 할 때 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)
의 주석을 삭제하면 위에서 언급 한 오류가 발생합니다.