0
所以我有一個JPanel
被拆分成另外兩個單獨的JPanel
(儘管這大多是不相關的)。在左側,我有一個GridBagLayout
,我已經組織起來在頂部有一個JLabel
,在它下面有一個JTextArea
,但是JTextArea
不是直接在JLabel
的下面。相反,這是空的空間,我不知道爲什麼它在那裏或如何解決它。我對Java一般而言並不陌生,因此我可能會錯過一些東西,但我嘗試了幾件事情來使它工作。我有下面的代碼以及它正在做什麼的視覺表示。任何幫助表示讚賞。爲什麼這個GridBagLayout有未使用的空白空間,我該如何擺脫它?
CODE
//LEFT SIDE
GridBagConstraints leftGBC = new GridBagConstraints();
JPanel leftSide = new JPanel(new GridBagLayout());
leftSide.setBorder(new EmptyBorder(inset, inset, inset, inset));
Font titleFont = bb5.comfortaa.deriveFont(Font.PLAIN, 16f);
leftGBC.gridx = 0;
leftGBC.gridy = 0;
leftGBC.weightx = 1;
leftGBC.weighty = 1;
leftGBC.anchor = GridBagConstraints.NORTH;
JLabel leftTitle = new JLabel("Objective");
leftTitle.setFont(titleFont);
leftTitle.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Color.BLACK));
leftGBC.fill = GridBagConstraints.HORIZONTAL;
leftSide.add(leftTitle, leftGBC);
leftGBC.gridy = 1;
leftGBC.anchor = GridBagConstraints.NORTH;
JTextArea objectiveArea = new JTextArea(objectiveText);
objectiveArea.setBackground(leftTitle.getBackground());
objectiveArea.setEditable(false);
objectiveArea.setFocusable(false);
objectiveArea.setFont(bb5.samsung1.deriveFont(16f));
objectiveArea.setLineWrap(true);
objectiveArea.setWrapStyleWord(true);
leftSide.add(objectiveArea, leftGBC);
VISUAL
是的工作!謝謝您的幫助! – Ryan