How to detect JFrame window minimize and maximize events?

Markel Mairs picture Markel Mairs · Jun 22, 2012 · Viewed 25.4k times · Source

Is there a way to an event listener to a JFrame object to detect when the user clicks the window maximize or minimize buttons?

Am using the JFrame object as follows:

JFrame frame = new JFrame("Frame");

Answer

tenorsax picture tenorsax · Jun 22, 2012

You can use WindowStateListener. How to Write Window Listeners tutorial demonstrates how to create window-related event handlers.