任何人都可以解釋爲什麼循環引用在後續代碼中設置兩次?Java Swing佈局管理器循環引用被設置兩次
//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));
爲什麼要到BoxLayout
鏈接回JPanel
容器明確,而不是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
好吧 - 現在看看,希望更清楚 – amphibient