【问题标题】:MigLayout on split into 2 rowsMigLayout 拆分为 2 行
【发布时间】:2013-09-13 14:49:36
【问题描述】:

我想知道在使用布局 (MigLayout) 时,我可以分成 2 行而不是 2 列吗?

panel.add(fname,"split 2");
panel.add(Fname,"wrap, pushx, growx");
panel.add(lname,"split 2");
panel.add(Lname,"wrap, pushx, growx");
panel.add(desc,"split 3,top,gaptop 3,gapright 0.5");
panel.add(new JLabel("PlaceHolder"),"top,gaptop 3");
panel.add(new JScrollPane(Desc),"grow,push,wrap");
panel.add(C,"split 2, Right");
panel.add(D,"wrap");

我希望标签“PlaceHolder”位于文本描述下方而不是旁边 有没有办法实现它? :)

【问题讨论】:

  • 考虑使用适当缩进的SSCCE
  • 使用另一行并使 scrollPane 跨越它。顺便说一句:请学习 java 命名约定并遵守它们

标签: java swing layout miglayout


【解决方案1】:

这是一个代码 sn-p,它显示了一个两列布局,每行有一个标签/字段对(在顶部),另外两个标签在彼此下方和跨越 textArea 的行的左侧:

MigLayout layout = new MigLayout("wrap 2, debug", "[][fill, grow]");
JComponent content = new JPanel(layout);
content.add(new JLabel("First Name:"));
content.add(new JTextField());
content.add(new JLabel("Last Name:"));
content.add(new JTextField());
content.add(new JLabel("Description"));
content.add(new JScrollPane(new JTextArea(20, 20)), "spany 3");
content.add(new JLabel("placeholder"));
content.add(new JLabel(""), "newline"); // dummy to keep the placeholder at top
content.add(new JButton("Ok"), "span, split 2, align r, tag ok");
content.add(new JButton("Cancel"), "tag cancel");

需要注意的几点:

  • 始终将尽可能多的配置放入布局/行/列约束中
  • working around a possible bug 需要虚拟标签
  • 按钮被标记为自动符合每个操作系统的大小和顺序指南

【讨论】:

  • 谢谢你,但现在我遇到了一个新问题prntscr.com/1qfuwj 有没有办法让它们都在左上角? :)
  • 不了解您的要求,请编辑您的问题并解释,最好使用 SSCCE
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-01
  • 2013-01-21
  • 2023-03-19
  • 1970-01-01
  • 1970-01-01
  • 2019-06-25
  • 2013-10-20
相关资源
最近更新 更多