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

I am using WindowBuilder for Eclipse Java.

When I make a button or menu (or something else), it creates fields nested inside the constructor. Is there a way to make them fields and then initialized in the constructor so that I can use them outside the constructor? Thank.

i.e.: FROM

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

TO

public JMenuBar menubar; 
public GUIFrame() {
    menuBar = new JMenuBar();
}
+5
source share
1 answer

There is a button for converting an element from "local to field".

Convert

If you want all components to be default fields: Windows โ†’ Settings โ†’ WindowBuilder โ†’ Swing โ†’ Code Generation โ†’ Find โ€œVariable Generationโ€ and select the โ€œFieldโ€ tab.

+12
source

All Articles