I have this panel which is using MigLayout to create cells for my content. Here's the code portion:
/ ====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");
And here is how it is being rendered:
I want the "Items in this Outfit:" label to sit right above the JList. However, the cell that has the JList is the one that is the "big" one, so my attempt to tell the label to align bottom and go by that list has failed. I've tried to manually set the heights of the rows and for the components when I add them to the panel with the cell code. Nothing seems to work. And I also can't figure out how to put a border on each cell just to confirm my suspicions that it is in fact the JList cell being tall that is causing the problem.
What am I doing wrong here, how might I fix it?
Thanks!
I would suggest
setLayout(new MigLayout("hidemode 3", "[400][0][400]", "[][][][]push[][]"));
and remove the , bottom, growy for your itemsLabel.
I haven't tested it, so no warranty ;-) Also adding debug could help:
new MigLayout("debug, hidemode 3", ...