1

In the Java Swing tutorials, in the How to Write an Internal Frame Listener section it provides demo code to capture the events of closing or minimising (iconifying) a JInternalFrame window.

The event of maximise and restore however are not captured in the demo and there seems to be no method to capture these events in the InternalFrameAdapter class or an a relative field in the InternalFrameEvent.

How can I capture the event that the user clicked on the maximise/restore button?

1 Answer 1

2

You might be able to use PropertyChangeListener and JInternalFrame#IS_MAXIMUM_PROPERTY:

//Add an internal frame listener so we can see
//what internal frame events it generates.
listenedToWindow.addInternalFrameListener(this);

listenedToWindow.addPropertyChangeListener(evt -> {
  String prop = evt.getPropertyName();
  JInternalFrame f = (JInternalFrame) evt.getSource();
  Object newValue = evt.getNewValue();
  if (JInternalFrame.IS_MAXIMUM_PROPERTY == prop) {
    String prefix;
    if (newValue == Boolean.TRUE) {
      prefix = "Internal frame maximized : ";
    } else {
      prefix = "Internal frame minimized : ";
    }
    String s = prefix + f;
    display.append(s + newline);
    display.setCaretPosition(display.getDocument().getLength());
  }
});
//...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.