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).

Bigger
  • 1,807
  • 3
  • 18
  • 28

1 Answers1

1

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?").

Normally, you track changes to an edited file in the GUI model class. Every time your model adds or removes a character, you set a dirty flag in the model that you check later.

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).

Your understanding of Swing appears to be backwards. The components don't drive the layout. The layout arranges the components.

Here's one example of a Swing character based text editor.

Here's a Stack Overflow question about a GUI builder editor.

Community
  • 1
  • 1
Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
  • I swear I had a valid reason not to track every method that changes the document while every one of them already called repaint, maybe to let external classes modify the document directly. My approach was to call a hash function for every object in the document, hash them into one, and compare it with the last known one. I ended up better sealing the document class and keeping track of the changes in a better way. – Bigger Jun 19 '13 at 01:23
  • As for the custom layout manager calls, where I wrote Component I ment to write Container. This one is working fine. – Bigger Jun 19 '13 at 01:25