Horizontal glue is not properly displaying [on hold]
I'm having an issue with a BoxLayout JPanel not properly displaying horizontal glue. I believe that I've narrowed down the issue to there being no extra horizontal space for the glue to pull, as a rigid area creates space between each panel with no problems. With that being said, I can't seem to find what component or setting is causing this.
Here's the method that contains the code in question (I've surrounded the section of code where I add the horizontal glue with a multiline comment):
public void initialize() {
scrollPanel.removeAll();
for (Item item : getController().getCart().getItemList()) {
//Container
itemContainerPanel = new JPanel();
itemContainerPanel.setBorder(new EmptyBorder(0, 10, 10, 0));
itemContainerPanel.setLayout(new BoxLayout(itemContainerPanel, BoxLayout.Y_AXIS));
//Content panel
itemPanel = new JPanel();
itemPanel.setLayout(new BoxLayout(itemPanel, BoxLayout.X_AXIS));
itemPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
//itemPanel.setBorder(new LineBorder(Color.BLACK));
itemContainerPanel.add(itemPanel);
//Details left
detailsLeftPanel = new JPanel();
detailsLeftPanel.setLayout(new BoxLayout(detailsLeftPanel, BoxLayout.Y_AXIS));
detailsLeftPanel.setAlignmentY(Component.TOP_ALIGNMENT);
titlePanel = new JPanel();
FlowLayout titlePanelLayout = new FlowLayout(FlowLayout.LEFT);
titlePanelLayout.setHgap(0);
titlePanelLayout.setVgap(0);
titlePanel.setLayout(titlePanelLayout);
productNameLabel = new JLabel();
productNameLabel.setAlignmentX(LEFT_ALIGNMENT);
productNameLabel.setAlignmentY(TOP_ALIGNMENT);
titlePanel.add(productNameLabel);
detailsLeftPanel.add(titlePanel);
datesBookedPanel = new JPanel();
FlowLayout datesBookedPanelLayout = new FlowLayout(FlowLayout.LEFT);
datesBookedPanelLayout.setHgap(0);
datesBookedPanelLayout.setVgap(0);
datesBookedPanel.setLayout(datesBookedPanelLayout);
datesBookedLabel = new JLabel();
datesBookedLabel.setAlignmentX(LEFT_ALIGNMENT);
datesBookedPanel.setAlignmentY(TOP_ALIGNMENT);
datesBookedPanel.add(datesBookedLabel);
detailsLeftPanel.add(datesBookedPanel);
//Value assignment
productNameLabel.setText(item.getProduct().getHotelName() + " - " +
item.getProduct().getRoomName() + " - Room " +
item.getProduct().getRoomId());
StringBuffer datesBookedBuffer = new StringBuffer("");
for (String date : item.getBookingDates()) {
datesBookedBuffer.append(date);
datesBookedBuffer.append(" ");
}
datesBookedLabel.setText("Date(s) booked: " + datesBookedBuffer.toString());
//Details right
detailsRightPanel = new JPanel();
detailsRightPanel.setLayout(new BoxLayout(detailsRightPanel, BoxLayout.Y_AXIS));
detailsRightPanel.setAlignmentY(Component.TOP_ALIGNMENT);
removePanel = new JPanel();
removePanel.setLayout(new BoxLayout(removePanel, BoxLayout.X_AXIS));
detailsRightPanel.add(removePanel);
cartItemPriceLabel = new JLabel();
cartItemPriceLabel.setAlignmentY(Component.CENTER_ALIGNMENT);
removePanel.add(cartItemPriceLabel);
removeBtn = new JButton("Remove");
removeBtn.setAlignmentY(Component.CENTER_ALIGNMENT);
removePanel.add(removeBtn);
//Value assignment
cartItemPriceLabel.setText("Price: $" + item.getItemPrice());
/* ITEM PANEL BUILD WITH HORIZONTAL GLUE */
itemPanel.add(detailsLeftPanel);
itemPanel.add(Box.createHorizontalGlue());
itemPanel.add(detailsRightPanel);
//Item separator line
JSeparator separator = new JSeparator(JSeparator.HORIZONTAL);
Dimension size = new Dimension(separator.getMaximumSize().width, separator.getPreferredSize().height);
separator.setMaximumSize(size);
itemContainerPanel.add(separator);
itemPanel.setMaximumSize(itemPanel.getPreferredSize());
scrollPanel.add(itemContainerPanel);
//Item action listeners
removeBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
getController().getCart().remove(item);
getController().removeItemFromCart(item);
getController().showCartView();
}
});
}
Any help would be appreciated. Thanks and have a nice day.