【发布时间】:2016-03-05 23:50:05
【问题描述】:
当我在我的程序中执行以下方法时,一些组件会在计时器用完时发生变化。例如,我创建了一个 jTextArea 的大小更改,而没有任何包含构造来更改其大小的事件。如果我先扩展 jTextArea 然后启动计时器,或者反之亦然,都没有关系。
//Show Debug Information for given Seconds with given Text
void giveUserInformation(String input, boolean function, int duration) {
//Debug information and label visibility handling
jLabelDebug.setVisible(true);
jLabelDebug.setText(input);
//Image
if (function)
jLabelDebug.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/ok-icon.png")));
else
jLabelDebug.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/Actions-edit-delete-icon.png")));
//Show duration
if (timerShowDurationRuns) {
timerShowDuration.cancel();
timerShowDuration = new Timer();
}
timerShowDurationRuns = true;
//fadeIn();
timerShowDuration.schedule(new TimerTask() {
@Override
public void run() {
jLabelDebug.setVisible(false);
timerShowDurationRuns = false;
//fadeOut();
}
}, duration * 1000);
setCursor(Cursor.getDefaultCursor());
}
【问题讨论】:
-
您将标签设置为不可见 - 这是更改内容的指令 - 以及 jtextArea 在哪里?
-
假设您正在使用布局管理器,当您更改组件的可见状态时,需要计算布局以补偿该组件的丢失(因为不可见组件不占用空间)
标签: java swing events timer freeze