How to make WindowBuilder create fields that are not nested in Eclipse, Java

好久不见. 提交于 2019-12-07 06:34:57

问题


I am using WindowBuilder for Eclipse Java.

When I make a Button or a Menu (or anything), it creates the fields nested inside of the constructor. Is there any way to make them fields and then initialized in the constructor so I can use them outside of the constructor? Thank you.

ie: FROM

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

TO

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

回答1:


There's a button to convert an element from "local to field".

If you want all components to be fields by default: Windows -> Preferences -> WindowBuilder -> Swing -> Code Generation -> Find "Variable generation" and select the "Field" tab.



来源:https://stackoverflow.com/questions/11803107/how-to-make-windowbuilder-create-fields-that-are-not-nested-in-eclipse-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!