Dim*_*gin 1 java swing layout-manager gridbaglayout
如何填充感兴趣的网格单元中可用的垂直和水平空间?
例如:
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);
Run Code Online (Sandbox Code Playgroud)
这会垂直填充单元格,但不会水平填充单元格。
c.fill = GridBagConstraints.HORIZONTAL
显然在该值后面添加VERTICAL
只会覆盖该值c.fill
OR
喜欢它们c.fill = GridBagConstraints.HORIZONTAL | GridBagConstraints.VERTICAL
也没有效果。
你应该使用:
GridBagConstraints gridConst = new GridBagConstraints();
gridConst.fill = GridBagConstraints.BOTH;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2565 次 |
最近记录: |