- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有 gridbaglayout 布局的 jpanel,其中我有几个 jtextfields、几个 jlabels、几个动态添加的 jbuttons。因此我不知道他们的具体命令,因此不能使用 panel.getComponent(count)。我查看了 api 是否有类似 getGridx(int x) 或 getGridy(int y) 的东西。没找到。有没有类似的方法?
最佳答案
最简单的解决方案可能是使用 GridBagLayout#getConstraints(Component)
并简单地遍历所有组件,直到找到与所需网格位置匹配的组件...
Component match = null;
GridBagLayout layout = ...
for (Component comp : getComponents()) {
GridBagConstraints gbc = layout.getConstraints(comp);
if (gbc.gridx = x && gbc.gridy = y) {
match = comp;
break;
}
}
关于java - 如何从具有 GridBagLayout 布局的 JPanel 中获取位于特定 gridx、gridy 中的组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19043373/
我正在尝试创建一个设置 JLabels 的程序,使用 GridBagLayout。 我想创建一个按钮,按下该按钮会删除某个 gridY 位置的所有内容。我该怎么做呢。谢谢。 最佳答案 简单。当您将这些
我正在尝试创建一个表单,但在使用 GridBagConstraints 时遇到困难。当我设置gridy时,它似乎不起作用。这是我的代码: thisWindow = new GridBagConstra
我在制作的游戏中无法正确布置某些组件。我的 GUI 由带有 BorderLayout 的外部 JFrame 组成,在 BorderLayout 的东侧我有一个带有 GridBagLayout 的 JP
我正在尝试使用 gridx 和 gridy 约束来定位我的按钮。但它们不起作用!如果我更改 gridx 和 gridy 变量,什么也不会发生。如果我将 fill to GridBagConstrain
我正在尝试使用 gridx 和 gridy 约束来创建如下所示的界面(忽略“下一步”按钮)。前两个 JLabel-JTextField 对工作正常,但我不确定我为其余 10 个字段设置了什么 grid
我有一个带有 gridbaglayout 布局的 jpanel,其中我有几个 jtextfields、几个 jlabels、几个动态添加的 jbuttons。因此我不知道他们的具体命令,因此不能使用
我有一个带有 gridbaglayout 布局的 jpanel,其中有几个 jtextfields、几个 jlabels、几个动态添加的 jbuttons。因此我无法知道它们的具体顺序,因此无法使用
我是一名优秀的程序员,十分优秀!