ComponentListener出了点问题。我使用它来检查某个组件是否调整了大小,如果是,则更新一些内容。
代码看起来像这样,尽管这可能对您没有多大用处:
@Override
public void componentResized(ComponentEvent e) {
// Graph resized, reposition slice nodes
Component c = e.getComponent();
if (graphHeight > 0) {
if (c == graph) {
int offset = (c.getHeight() - graphHeight) / 2;
if (offset != 0) {
try {
controller.shiftSlice1NodesY(offset);
} catch (GraphIntegrityException e1) {
logger.error(e1.getMessage(), e1);
}
graphHeight = c.getHeight();
}
}
} else {
graphHeight = c.getHeight();
}
}对于我的代码的一部分,我需要禁用这个侦听器。它看起来像这样:
graph.removeComponentListener(this);
controller.parseFile(filename);
graph.addComponentListener(this);在我再次添加组件侦听器之前,一切都很顺利。此时,componentResized方法被调用了大约20次。它可能缓冲了我所能看到的调整大小事件。有人知道这是怎么回事吗?
发布于 2010-03-30 07:12:39
看起来您正在尝试修改事件调度线程(EDT)的组件。这在AWT中甚至都不是一个好主意,更不用说Swing了。
除了在正确的线程上获得所有AWT/Swing内容之外,修复的一部分应该是获得侦听器的检查状态,以查看它是否应该执行其主体,而不是试图删除和添加侦听器。
https://stackoverflow.com/questions/2541809
复制相似问题