순환 참조가 followig 코드에서 두 번 설정되는 이유를 설명 할 수 있습니까?자바 스윙 레이아웃 관리자 순환 참조가 두 번 설정됩니다
//declare panel
this.cntnrPnl = new JPanel();
//define layout manager for the panel - but why circ ref?
this.cntnrPnl.setLayout(new BoxLayout(this.cntnrPnl, BoxLayout.Y_AXIS));
이유는 JPanel
컨테이너에 다시 BoxLayout
연결을 명시 적으로 대신 JPanel.setLayout
의 장면 뒤에 자신을 설정하고 코드 소형화에 대한 BoxLayout
에서 세터를 사용하여 수행하는 것이 필요하다?
예컨대 :
this.cntnrPnl.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
//and then in JPanel.setLayout have something line
_layout.setContainer(this);
순환 참조가 있지만 왜 클라이언트 코드가'Container'를'BoxLayout' 생성자에 전달하여 연결해야하는지에 대한 질문은 아닌 것 같습니다. –
좋은 지적. 문구를 다시 말하자면 – amphibient
OK - 확인해보세요. 잘하면 더 명확 해집니다. – amphibient