NetBeans 为 UI 生成代码
为什么当我在 NetBeans 中生成一个简单的 JFrame 代码时,它总是给我一个很长的简单 GUI 代码,有点乱,有没有插件?或者仅为组件生成 UI 代码的编译器?在他们的位置上??
Why is it that when I generate a code for a simple JFrame in NetBeans it always give me a very long code for a simple GUI, it's kinda messy, is there any plug-in? or compiler that will generate UI code just for the components? in their position??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Netbeans UI 编辑器默认使用供此类自动工具使用的布局 (
GroupLayout
)。生成的代码通常很冗长——几乎所有自动生成的代码都是如此!无论如何,您无法触及此代码(至少在 Netbeans 内部),所以您为什么要关心呢?如果您需要简单的代码,请了解每个 Swing 布局的属性并使用它们对表单进行手动编码,或通过 Netbeans 编辑器进行编码。作为额外的好处,您将可以更好地控制表单外观(当表单变得更加复杂时,默认布局很容易表现得不符合预期)。
The Netbeans UI editor uses by default a layout (
GroupLayout
) that is meant to be used by such automatic tools. The resulting code is generally verbose -- as is almost any automatically generated code! Anyway, you can't touch this code (from inside Netbeans, at least), so why would you care?If you need simple code, learn the properties of each Swing layout and use them to hand-code your forms, or through the Netbeans editor. As an added bonus, you will have far better control on your forms appearance (the default layout can easily behave not as intended when your forms gets more complex).