java – MigLayout中的Span / Grow错误?
作者:互联网
以下是接近我想要的,并做我期望的:
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import net.miginfocom.swing.MigLayout;
public class MigBug extends JFrame {
public static void main(String args[]) {
MigBug migbug = new MigBug();
migbug.pack();
migbug.setVisible(true);
}
public MigBug() {
JPanel content = new JPanel();
content.setLayout(new MigLayout("fill, debug"));
content.add(new JLabel("Label 1"));
content.add(new JComboBox());
content.add(new JLabel("Label 2"));
content.add(new JTextField(25), "growx, wrap");
content.add(new JLabel("BIG"), "span, w :400:, h :200:, growy");
setContentPane(content);
}
}
但是,如果我做出以下更改:
content.add(new JLabel("BIG"), "span, w :400:, h :200:, grow");
即.将跨区组件更改为在x和y中增长,Label 1单元格以x增长,即使它不应该.
有谁知道我可以解决这个问题?
解决方法:
找到了解决方法,但并不完全令人满意.根据this forum post和this forum post,MigLayout从计算组件大小切换到计算涉及跨度的列大小.在布局约束中用“filly”替换“fill”,然后为每个应该允许增长的列添加“增长”的列约束似乎可以修复它.
工作代码:
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import net.miginfocom.swing.MigLayout;
public class MigBug extends JFrame {
public static void main(String args[]) {
MigBug migbug = new MigBug();
migbug.pack();
migbug.setVisible(true);
}
public MigBug() {
JPanel content = new JPanel();
content.setLayout(new MigLayout("filly, debug", "[][grow][][grow]"));
content.add(new JLabel("Label 1"));
content.add(new JComboBox());
content.add(new JLabel("Label 2"));
content.add(new JTextField(25), "growx, wrap");
content.add(new JLabel("BIG"), "span, w :400:, h :200:, grow");
setContentPane(content);
}
}
标签:java,miglayout 来源: https://codeday.me/bug/20190627/1301828.html