我正在尝试学习如何使用MigLayout。这是我所拥有的,它看起来像我想要的样子:

相关代码如下:
JPanel authorsPanel = new JPanel(new MigLayout("", "[]20[][]", "[][][][][][]"));
JTable authorsTable = new JTable(authorstableModel);
// Configure labels
JLabel firstNameL = new JLabel("First Name:");
JLabel middleNameL = new JLabel("Middle Name:");
JLabel lastNameL = new JLabel("Last Name:");
JLabel blurbL = new JLabel("Blurb/Bio:");
// Configure text fields
firstName = new JTextField("No Selection", 20);
firstName.setEditable(false);
firstName.setForeground(Color.gray);
middleName = new JTextField("No Selection", 20);
middleName.setEditable(false);
middleName.setForeground(Color.gray);
lastName = new JTextField("No Selection", 20);
lastName.setEditable(false);
lastName.setForeground(Color.gray);
blurb = new JTextArea("No Selection", 10, 40);
blurb.setEditable(false);
blurb.setForeground(Color.gray);
blurb.setLineWrap(true);
// Add components to authorsPanel
authorsPanel.add(new JScrollPane(authorsTable), "span 1 6");
authorsPanel.add(firstNameL);
authorsPanel.add(firstName, "wrap");
authorsPanel.add(middleNameL);
authorsPanel.add(middleName, "wrap");
authorsPanel.add(lastNameL);
authorsPanel.add(lastName, "wrap");
authorsPanel.add(blurbL);
authorsPanel.add(new JScrollPane(blurb), "span 2 2");我觉得我好像真的没做对。这似乎没有区别,无论我使一个组件“跨度16”或“跨度14”,这是令人不安的。此外,MigLayout JTextArea的大小是在启动时确定的,并且似乎对MigLayout内容的大小没有响应,它只影响定位。
我想学习如何在这个场景中更好地控制我使用MigLayout所做的事情,因为我甚至在开始使用它时就遇到了一堆问题。我也想用正确的方式去做。
发布于 2015-07-29 20:03:20
第一个技巧:将它设置为debug可以让您看到MigLayout已经声明的区域以及组件是如何分布在这些区域上的。在这样的情况下,这可能非常有用。
authorsPanel,我认为您希望将其设置为spany。默认情况下会填满所有可用空间。JScrollPane(blurp)也是如此,应该是spany 2。
你说你有一个问题是得到的是正确的大小,但没有什么应该是比较的图片,所以我不能给你任何提示。您可能希望查看第一段代码,其中声明了初始MigLayout:
JPanel authorsPanel = new JPanel(new MigLayout("", "[]20[][]", "[][][][][][]"));这是描述元素应该如何使用grow/fill或其他方式的地方。
看看:http://www.migcalendar.com/miglayout/whitepaper.html和http://www.miglayout.com/cheatsheet.html
https://stackoverflow.com/questions/31604355
复制相似问题