如何填充感兴趣的网格单元中可用的垂直和水平空间?
例如:
JTextArea file1 = new JTextArea();
file1.setBorder(BorderFactory.createLineBorder(Color.black));
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 1;
c.weightx = 1.0 / ELEMENTS_IN_WIDTH;
c.weighty = 0.9;
c.insets = new Insets(PAD, PAD, PAD, PAD);
c.fill = GridBagConstraints.VERTICAL;
mainPanel.add(file1, c);
这会垂直填充单元格,但不会水平填充单元格。
显然添加c.fill = GridBagConstraints.HORIZONTAL
VERTICAL
之后value 只会覆盖 c.fill
的值
OR
像 c.fill = GridBagConstraints.HORIZONTAL | GridBagConstraints.VERTICAL
一样对待他们也没有达到目的。
最佳答案
您应该使用:
GridBagConstraints gridConst = new GridBagConstraints();
gridConst.fill = GridBagConstraints.BOTH;
关于java - GridBagConstraints 填充垂直和水平,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33827543/