【发布时间】:2017-12-16 10:45:16
【问题描述】:
我有以下代码,我尝试使一些 jLabels/jComboBox 可见/不可见,并移动那些可见的位置 在 jRadioButton 点击时。
问题是位置仅在第二次点击时更新。
private void SingleButtonActionPerformed(java.awt.event.ActionEvent evt) {
this.serverLabel.setVisible(true);
this.serverList.setVisible(true);
this.serverLabel.setLocation(this.hostGroupLabel.getLocation().x, this.cpuCountSpinner.getLocation().y);
this.serverList.setLocation(this.cpuCountSpinner.getLocation().x, this.cpuCountSpinner.getLocation().y);
this.jXDatePickerStartDate.setLocation(153, jXDatePickerStartDate.getLocation().y);
this.requestedRamLabel.setVisible(false);
this.ramText.setVisible(false);
this.cpuLabel.setVisible(false);
this.cpuCountSpinner.setVisible(false);
}
【问题讨论】:
-
您可能想看看this answer,即使它可能无法解决您的问题。也只有我们不能真正帮助你的行动。发布更多代码
-
我正在检测 JRadioButton 状态变化,但正如我提到的,只有在他已经点击后再次点击按钮时,位置正在改变。
-
1) 您可能需要重新绘制框架。 2) 永远不要使用 setLocation 方法。请改用适当的布局管理器。
-
您是否尝试过调用
revalidate触发新的布局通道和repaint触发新的绘制通道 -
当我使用 revalidate 然后重新绘制它根本不起作用。
标签: java swing layout-manager