0

I want to get my event listener called when the component is repainted (JComponent). I read about different Event Listeners but none seems to be the correct one for Invalidate or Repaints. Any way to do this?

Why I want this: I'm trying to get notified when there is some change in a control, in order to fire the method that tracks the changes (as in the file has changed, "do you want to save changes?").

Another use for this is for manually invoking the custom layout manager of a non-added-to-the-container-but-drawn component (this one is kind of complex, it's for a GUI editor program).

4

1 回答 1

1

为什么我想要这个:我试图在控件发生某些更改时收到通知,以便触发跟踪更改的方法(如文件已更改,“你想保存更改吗?”)。

通常,您在 GUI 模型类中跟踪对已编辑文件的更改。每次您的模型添加或删除一个字符时,您都会在模型中设置一个脏标志,以便稍后检查。

另一个用途是手动调用非添加到容器但绘制的组件的自定义布局管理器(这个有点复杂,它用于 GUI 编辑器程序)。

您对 Swing 的理解似乎是倒退的。组件不驱动布局。布局安排组件。

这是基于 Swing字符的文本编辑器的一个示例。

这是关于GUI builder editor的 Stack Overflow 问题。

于 2013-06-18T15:22:50.037 回答