gpt4 book ai didi

java - MigLayout 分成 2 行

转载 作者:行者123 更新时间:2023-12-01 14:08:38 25 4
gpt4 key购买 nike

我想知道在使用布局 (MigLayout) 时我可以分成 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”位于文本描述下方而不是旁边有办法实现吗? :)

enter image description here

最佳答案

下面是一个代码片段,显示了一个两列布局,每行有一个标签/字段对(位于顶部),其他两个标签位于彼此下方且位于跨越 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 需要虚拟标签
  • 按钮被标记为自动遵守每个操作系统的大小和顺序指南

关于java - MigLayout 分成 2 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18709680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com