简体   繁体   English

带有Java Swing的Netbeans GUI Builder; 组织小部件最简单的方法是什么?

[英]Netbeans GUI Builder with Java Swing; What's the easiest way to organize Widgets?

I'm developing a GUI application rapidly using a GUI buidler (Netbeans). 我正在使用GUI Buidler(Netbeans)快速开发GUI应用程序。 I am frustrated with the Swing widgets... when I resize one the rest seem to "reorganize" themselves in the wrong places. 我对Swing小部件感到沮丧……当我调整一个小部件的大小时,其余的似乎在错误的地方“重组”了自己。

What do you guys use to tame such chaos? 你们用什么来驯服这种混乱? I was thinking of tables.... but couldn't find any in the Netbeans Palette. 我在考虑表格...。但是在Netbeans面板中找不到任何表格。

Regards 问候

Use MigLayout . 使用MigLayout

If you want to use pure Swing, use GridBagLayout and be prepared for a lot of pain. 如果要使用纯Swing,请使用GridBagLayout并为此付出很多准备。

Coding GUI manually should be the preferred way (at least for the sake of maintainability). 手动编码GUI应该是首选方式(至少出于可维护性考虑)。 There are a few, open source, Swing layout managers that are pretty good at it. 有一些非常擅长的开源Swing布局管理器。

Someone has mentioned MigLayout, which allows any layout, is quite simple to use, but often requires some tweaking until you get what you want. 有人提到过MigLayout,它允许任何布局,使用起来非常简单,但通常需要进行一些调整,直到获得所需的内容。

On the other hand, you also can use DesignGridLayout , which is suitable for most common layouts and is easier to use (thanks to its fluent API) than MigLayout. 另一方面,您还可以使用DesignGridLayout ,它适用于大多数常见的布局,并且比MigLayout易于使用(由于其流畅的API)。

You are never forced to use a single layout manager. 您永远不会被迫使用单个布局管理器。 That is the problem with using an IDE to design a GUI. 那就是使用IDE设计GUI的问题。 You get bloated code because the tool uses a single layout manager with multiple confusing constraints in order to get the form layout out the way you drag and drop it. 之所以会出现膨胀的代码,是因为该工具使用具有多个令人困惑的约束的单个布局管理器,以便以拖放方式获得表单布局。

Create your forms manually and use nested panels with different layout managers to layout the components as desired. 手动创建表单,并使用具有不同布局管理器的嵌套面板按需要对组件进行布局。 The code is easier to maintain and understand. 该代码更易于维护和理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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