5

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();
}
Cole Canning
  • 237
  • 3
  • 11

1 Answers1

14

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

Convert

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

mortalis
  • 2,060
  • 24
  • 34
Chris911
  • 4,131
  • 1
  • 23
  • 33