你能帮我理解这里发生了什么吗?我查阅了Javadoc:JFrame有一个setLayout方法。所以,共享错误出现的原因对我来说是个谜。
public class View extends JFrame {
public View(){
// LayoutManager for the whole frame.
this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
}
}
结果
Exception in thread "main" java.awt.AWTError: BoxLayout can't be shared
at javax.swing.BoxLayout.checkContainer(BoxLayout.java:465)
at javax.swing.BoxLayout.invalidateLayout(BoxLayout.java:249)
at java.awt.Container.invalidate(Container.java:1583)
at java.awt.Component.invalidateIfValid(Component.java:2957)
at java.awt.Container.setLayout(Container.java:1484)
at javax.swing.JFrame.setLayout(JFrame.java:605)
at View.<init>(View.java:16)
at Init.main(Init.java:6)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)