我正在使用 Swing GroupLayout,我对这些值GroupLayout.DEFAULT_SIZE
和GroupLayout.PREFERRED_SIZE
. 我永远不知道什么时候在方法中使用它们中的每一个GroupLayout.addComponent(Component, int, int, int)
。
假设我有这个代码:
GroupLayout l = ...;
l.setHorizontalGroup(l.createSequentialGroup()
.addComponent(tf1)
.addComponent(tf2));
l.setVerticalGroup(l.createParallelGroup()
.addComponent(tf1)
.addComponent(tf2));
JTextField
在一条线上有两个s 布局GroupLayout
(水平顺序组和垂直平行组)。如果我现在调整窗口大小,两个组件都会获得可用空间(每个 50%)。但我只希望第一个文本字段水平增长/缩小,只有第二个文本字段垂直增长/缩小。我应该使用什么min、pref和max值来实现这一点?我知道我可以尝试一下,看看哪种组合有效,但我想知道这个问题背后的原因。