5

我正在为 Eclipse Java 使用 WindowBuilder。

当我制作按钮或菜单(或任何东西)时,它会创建嵌套在构造函数内的字段。有没有办法让它们成为字段,然后在构造函数中初始化,以便我可以在构造函数之外使用它们?谢谢你。

即:从

public GUIFrame() {
    JMenuBar menuBar = new JMenuBar();
}

public JMenuBar menubar; 
public GUIFrame() {
    menuBar = new JMenuBar();
}
4

1 回答 1

13

有一个按钮可以将元素从“本地到字段”转换。

转变

如果您希望所有组件默认为字段:Windows -> Preferences -> WindowBuilder -> Swing -> Code Generation -> 找到“Variable generation”并选择“Field”选项卡。

于 2012-08-07T18:07:54.357 回答