Swing and lazy loading components

ぐ巨炮叔叔 提交于 2019-12-04 14:33:25

When you use lazy loading, you should always use the getter each time you access the member variables. This is a fundamental part of lazy loading.

However, in this case you described, there is no reason to use lazy loading. I have to wonder if the author of Visual Editor didn't just have some thing for lazy loading where he felt it always needed to be used, or just decided that he wanted to use it in the tool for some arbitrary reason.

You are exactly right about UI's where components are generally all loaded when the panel is constructed because they're all visible. There are some cases where parts of a panel may appear and disappear based on other choices on the panel, and it's conceivable that you could use lazy loading in these cases. My point of view, however, is that people are likely to click around an interface anyways and use all the different tabs and options, so you might as well load everything to begin with.

Obviously, there's something different going on when you're talking about loading data. If you have a drop-down that's hidden when the panel comes up and has a lot of information if loaded, you may want to not load the drop-down until it becomes visible. I still see no reason not to instantiate the drop-down right away, though, even though it's hidden.

I would not consider lazy loading to be the norm behavior for a panel at all. I could not offer a reason why Visual Editor chose to generate code in this manner.

I'm not a big fan of the code WYSIWYG (UI) editors generate

Me either.

Is there actually any use for lazy loading in this case?

I don't think so, the creation of the component takes no time so all components should be visible when the GUI is displayed.

To me the bigger concern is the data. If your data for components like combo boxes and tables comes from a database you may not want to load it all up front.

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