gpt4 book ai didi

java - GridBagConstraints 填充垂直和水平

转载 作者:行者123 更新时间:2023-12-01 16:55:20 26 4
gpt4 key购买 nike

如何填充感兴趣的网格单元中可用的垂直和水平空间?

例如:

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 的值

ORc.fill = GridBagConstraints.HORIZONTAL | GridBagConstraints.VERTICAL 一样对待他们也没有达到目的。

最佳答案

您应该使用:

GridBagConstraints gridConst = new GridBagConstraints();
gridConst.fill = GridBagConstraints.BOTH;

关于java - GridBagConstraints 填充垂直和水平,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33827543/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com