gpt4 book ai didi

java - MigLayout,为什么这个单元格使用了额外的空间?

转载 作者:行者123 更新时间:2023-12-01 16:20:39 28 4
gpt4 key购买 nike

我有这个面板,它使用 MigLayout 为我的内容创建单元格。这是代码部分:

/ ====Layout====
setLayout(new MigLayout("hidemode 3", "[400][0][400]", "[][][][][][]"));

Border border = BorderFactory.createLineBorder(Color.WHITE, 0);
//setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.gray));
// ====Components====

// ===Information Displays===
JLabel invName = new JLabel("inventory name");
invName.setBorder(border);
invName.setEnabled(false);
add(invName, "cell 0 0, growx");
JTextField displayName = new JTextField("display name");
add(displayName, "cell 0 1, growx");
JComboBox category = new JComboBox();
category.setEditable(true);
category.setModel(new DefaultComboBoxModel<>(new String[] {"Tops", "Skirts", "Pants", "Dresses", "Shorts"}));
add(category, "cell 0 2, growx");
JButton updateFields = new JButton("Update");
add(updateFields, "cell 0 3");
JLabel itemsLabel = new JLabel("Items in this Outfit:");
itemsLabel.setBorder(border);
add(itemsLabel, "cell 0 4, bottom, growy");
JList<String> itemsInOutfit = new JList<>();
itemsInOutfit.setVisibleRowCount(8);
itemsInOutfit.setModel(new AbstractListModel<String>() {
String values[] = {"item 1",
"item 2",
"item 3",
"item 4",
"item 5",
"item 6",
"item 7",
"item 8",
"item 9",
"item 10"
};
@Override
public int getSize() {
return values.length;
}

@Override
public String getElementAt(int index) {
return values[index];
}
});
JScrollPane scrollPane = new JScrollPane(itemsInOutfit);
add(scrollPane, "cell 0 5, growx, bottom");
JButton goToItem = new JButton("Go to Item");
add(goToItem,"cell 0 6");

// ===Items in Outfit JList===

// ===Picture Box===

// ---Picture Box buttons---

JToolBar picturesBar = new JToolBar();

JButton leftArrowBtn = new JButton();
leftArrowBtn.setToolTipText("Previous Image");
//leftArrowBtn.setIcon(new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/back.svg"));
picturesBar.add(leftArrowBtn);

JButton rightArrowBtn = new JButton();
rightArrowBtn.setToolTipText("Next Image");
//rightArrowBtn.setIcon(new FlatSVGIcon("com/formdev/flatlaf/demo/icons/forward.svg"));
picturesBar.add(leftArrowBtn);

JButton addImageBtn = new JButton();
addImageBtn.setToolTipText("Add Image");
addImageBtn.setIcon(UIManager.getIcon("Tree.openIcon"));
picturesBar.add(addImageBtn);

JButton deleteImageBtn = new JButton();
deleteImageBtn.setToolTipText("Delete Image");
deleteImageBtn.setIcon(UIManager.getIcon("Tree.openIcon"));
picturesBar.add(deleteImageBtn);
picturesBar.setFloatable(false);
add(picturesBar, "cell 2 6, bottom, span");

// ---Picture Box Display---
JLabel pictureGallery = new JLabel();
pictureGallery.setBorder(border);
pictureGallery.setIcon(new ImageIcon(new ImageIcon("C:/users/saman/documents/projects/MyCloset/src/main/resources/the_storm_couple.jpg").getImage().getScaledInstance(400, -1, Image.SCALE_DEFAULT)));
add(pictureGallery,"cell 2 0, span 1 6");

这是它的渲染方式:

我希望“此服装中的元素:”标签位于 JList 的正上方。然而,具有 JList 的单元格是“大”单元格,因此我尝试告诉标签对齐底部并遵循该列表失败了。当我使用单元代码将行和组件添加到面板时,我尝试手动设置行和组件的高度。似乎什么都不起作用。而且我也无法弄清楚如何在每个单元格上放置边框,只是为了证实我的怀疑,即实际上是 JList 单元格太高导致了问题。

我在这里做错了什么,我该如何解决它?

谢谢!

最佳答案

我建议

setLayout(new MigLayout("hidemode 3", "[400][0][400]", "[][][][]push[][]"));

并删除您的 itemsLabel 的、bottom、growy

我还没有测试过,所以没有保证;-)另外添加调试可能会有所帮助:

new MigLayout("debug, hidemode 3", ...

关于java - MigLayout,为什么这个单元格使用了额外的空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62293756/

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