简体   繁体   中英

Eclipse -> Java -> accessing controls from functions

Newbie, so be kind.

Using eclipse for Java EE, added a WindowsBuilder Application Form. Added some controls. Then created in the same java file as the ui a function, at the bottom, called ResetUI() that I made public.

In NetBeans, I can access from that functions my controls, you know, simply empty the textboxes etc.

In Eclipse, I can't. For example: jftSourceWidth.setText("");

will show the lightbulb saying "jftSourceWidth cannot be resolved".

Why, oh why???

I mean, its all in the same source, the same works in NetBeans. How do I fix it?

Thanks,

Eclipse WindowBuilder elements are local variables by default, and as such, cannot be accessed by main or any scopes that are not the function initializing the window. You need to use the "convert to field" feature of WindowBuilder:

在此处输入图片说明

It should now be accessible in all non-static scopes of your window class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM