GroupLayout
我为我的面板使用 a :
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 是我的项目的名称,Panel 是从 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