我用一個GroupLayout
我的面板:IllegalStateException異常中的GroupLayout
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup()
.addComponent(title_panel)
.addComponent(subtitle_panel)
);
layout.setVerticalGroup(
layout.createSequentialGroup()
.addComponent(title_panel)
.addComponent(subtitle_panel)
);
即使我定義了水平和垂直兩個團體,但它仍然給了我一個
java.lang.IllegalStateException
但並非總是如此。有時它做到了,有時卻沒有。即使有這種例外,我的GUI工作並顯示我想要的。
我想我有一個答案的開始。當我第一次顯示面板的框架時,我沒有這個例外。但是,當我第二次展示它時,它給了我這個例外。這就像程序在框架的兩次啓動之間保留了我的groupLayout的一部分,或類似的東西。
儘管有這種例外,它仍然很有效^^'當我自己的代碼纏住我時,我不喜歡!
這是我得到的錯誤(DERP是我謨的名稱,面板由JPanel的繼承類)的例子:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: derp.Panel[,0,0,0x0,invalid,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=] is not attached to a horizontal group
at javax.swing.GroupLayout.checkComponents(GroupLayout.java:1086)
at javax.swing.GroupLayout.prepare(GroupLayout.java:1040)
at javax.swing.GroupLayout.layoutContainer(GroupLayout.java:910)
at java.awt.Container.layout(Container.java:1503)
at java.awt.Container.doLayout(Container.java:1492)
at java.awt.Container.validateTree(Container.java:1688)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validate(Container.java:1623)
at javax.swing.RepaintManager$2.run(RepaintManager.java:679)
at javax.swing.RepaintManager$2.run(RepaintManager.java:677)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:676)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1650)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
at java.awt.EventQueue.access$200(EventQueue.java:100)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
juin 27, 2013 4:39:35 PM io.socket.IOConnection transportMessage
你說它有時會這樣做,而不是其他 - 它在什麼條件下做到這一點?連續運行同一個程序?一些代碼更改後?一個小例子在這裏會很好。 – arcy
我甚至不知道!看起來沒有特殊的條件。或者如果有的話,我還沒有找到它們。該面板所在的框架連接到服務器。當我重新啓動服務器後第一次啓動它時,我認爲該框架沒有創建異常。但不到5分鐘後,我重新啓動服務器,在我啓動框架時出現異常-_-當我更改一些代碼時,有時會出現,有時候不會... – Sara