gpt4 book ai didi

java - 在文本字段中输入文本时,GridBagLayout 不断调整大小

转载 作者:行者123 更新时间:2023-12-01 22:42:49 25 4
gpt4 key购买 nike

我在使用 SwingBuilder 运行 groovy 中的 GridBagLayout 时遇到问题。我猜问题是 GridBagLayout 而不是 Groovy,所以我认为这在 Java 中也是一样的。

我有以下简单的布局:

new SwingBuilder().edt {
frame(title: 'test', defaultCloseOperation: JFrame.EXIT_ON_CLOSE, pack: true, show: true) {
gridBagLayout()
widget(textPane(background: java.awt.Color.RED), constraints: gbc(gridx:0, gridy: 0, weightx: 0.5, weighty: 1, fill: GBC.BOTH, gridheight: GBC.REMAINDER))
widget(textPane(background: java.awt.Color.GREEN), constraints: gbc(gridx: 1, gridy: 0, weightx: 0.5, weighty: 1, fill: GBC.BOTH))
label(text: "test label", background: java.awt.Color.BLUE, opaque: true, constraints: gbc(gridx: 1, gridy: 1, weightx: 0.5, fill: GBC.BOTH))
}
}

我想要一个窗口,左侧有一个文本 Pane ,正好占据窗口的 50%。在窗口的右侧(另外 50%)有另一个文本 Pane ,其下方(但仅采用所需的最小尺寸)有一个标签。

上面的代码可以工作并创建我想要的窗口,但是一旦我开始在左侧文本 Pane 中键入内容,左侧将开始占用更多空间(超过 50%)窗口)。

如何实现上述布局,以便无论在文本 Pane 中输入什么文本,两侧始终为 50:50?

最佳答案

I would like to have a window, with a text pane on the left side taking exactly 50% of the window.

那么您应该为这两个组件使用带有 GridLayout 的面板。

On the right side of the windows (the other 50%) another text pane and below that (but only taking minimum required size) a label.

然后可能是一个 BorderLayout,其中文本 Pane 添加到“CENTER”,标签添加到“PAGE_END”。

关于java - 在文本字段中输入文本时,GridBagLayout 不断调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25836533/

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