BoxLayout JPanel에 가로 접착제가 올바르게 표시되지 않는 문제가 있습니다. 나는 단단한 영역이 문제없이 각 패널 사이에 공간을 생성하기 때문에 접착제를 당길 수있는 여분의 수평 공간이 없다는 문제를 좁혔다 고 생각한다. 그 말로는, 어떤 구성 요소 나 설정이이 문제를 일으키는 지 찾을 수 없습니다. 두 JPanels 사이의 수평 접착제가 의도 한대로 작동하지 않습니다.
여기에 (내가 여러 줄의 코멘트와 함께 수평 접착제를 추가 어디 코드의 부분을 포위 한) 문제의 코드를 포함하는 방법이다 :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);
//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);
/* ITEM PANEL BUILD WITH HORIZONTAL GLUE */
itemPanel.add(detailsLeftPanel);
itemPanel.add(Box.createHorizontalGlue());
itemPanel.add(detailsRightPanel);
}
어떤 도움을 주시면 감사하겠습니다. 감사합니다. 좋은 하루 되세요.
편집 :
I 상기 부호 부의 출력을 표시하는 화상
을 포함했다. 이미지에 그려진 빨간색 선은 가로 접착제가 놓여있는 곳을 보여줍니다. 접착제는 가격표가있는 패널을 밀고 오른쪽의 버튼을 제거하여 창 너비를 채우지 만 그렇지 않습니다.
더 나은 도움을 받으려면 [MCVE] 또는 [Short, Self Contained, Correct Example] (http://www.sscce.org/)를 게시하십시오. –
힌트 : 귀하의 질문을 게시하기 전에 문제의 설명에 기여하지 않는 클래스의 모든 종속성을 제거하십시오. 누가 알아? 어쩌면 간단한 예제를 통해 문제를 직접 발견 할 수 있습니다. –