Not sure if it was any different back then with Java 6, but currently one could listen to graphicsConfiguration property changes on the top-level window:
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
public class SampleFrame extends JFrame {
private final JTextArea log = new JTextArea();
public SampleFrame() {
super("Sample Window");
log.setEditable(false);
log.setLineWrap(true);
logGC("Initial");
super.add(new JScrollPane(log));
super.addPropertyChangeListener("graphicsConfiguration",
evt -> logGC("Changed"));
}
private void logGC(String label) {
Document text = log.getDocument();
try {
Object gc = super.getGraphicsConfiguration();
text.insertString(text.getLength(), String.format("%s: (%x) %s\n\n",
label, System.identityHashCode(gc), gc), null);
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(() -> {
SampleFrame window = new SampleFrame();
window.setDefaultCloseOperation(EXIT_ON_CLOSE);
window.setSize(640, 480);
window.setLocationRelativeTo(null);
window.setVisible(true);
});
}
}
I can see changes to the graphicsConfiguration of the application window are notified on system display settings changes, moving the application window to another monitor, connecting or disconnecting monitors from the system.