【发布时间】:2015-10-14 18:16:58
【问题描述】:
我正在尝试学习如何使用 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");
我觉得我做的不太对。我是否制作一个令人不安的组件“span 1 6”或“span 1 4”似乎没有区别。此外,blurb JTextArea 的大小在启动时确定,而且似乎对 MigLayout 的大小没有反应,它只影响定位。
我想学习如何更好地控制我在这种情况下使用 MigLayout 所做的事情,因为我遇到了很多问题,甚至开始进行这项工作。我也想以正确的方式来做。
【问题讨论】:
标签: java swing user-interface miglayout