我想复制图示例:你如何让MiGLayout的行为像缠绕布局?
使用MiGLayout。我尝试了一些组合,但是我很难让 在容器缩小时自动将 包装到新行中。
有人可以提供一个工作的例子吗?
编辑: 这里是该程序的外壳:
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
public class MiGTest extends JFrame{
private JPanel jPanel;
private JButton jButton;
public static void main(String[] args) {
new MiGTest().setVisible(true);
}
public MiGTest(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new MigLayout("debug"));
initComponents();
addComponents();
pack();
}
private void addComponents() {
add(jPanel);{
for (int i = 0; i < 10; i++) {
jPanel.add(new JButton("" + i));
}
}
}
private void initComponents() {
jPanel = new JPanel(new MigLayout("debug"));
jButton = new JButton("Test");
}
}
听起来好像你试图将一个方形的钉子推入圆孔。为什么在需要不同的布局效果时使用MiGLayout? – 2011-04-19 12:04:14
@Hovercraft引用自miglayout.com:“你永远不必再次切换到另一个布局管理器!”。如果事实证明MigLayout不能做到这一点,我将使用Wrap Layout代替。但我很想知道这是否可能。 – Datoraki 2011-04-19 12:22:21
我认为MiGLayout支持这一点并将其称为单元格内流:有一个包含多个组件的单元,它们将像这样流动。 – 2011-04-19 12:46:43