Note that there are some explanatory texts on larger screens.

plurals
  1. POJInternalFrame activate/deactivate events fired multiple times
    text
    copied!<p>In my application, in a JDesktopPane I have added few JInternalFrames. Activation and deactivation of JInternalFrames happen normally, until one of the JInternalFrame is maximized. After that, activating an internalframe programmatically, fires internalFrameActivated, internalFrameDeactivated events multiple times. Why it is called many times? This I have observed in WindowsLookAndFeel only</p> <pre><code>public class IFTest { public static void main(String[] args) { try { UIManager.setLookAndFeel(new WindowsLookAndFeel()); } catch (UnsupportedLookAndFeelException e) { e.printStackTrace(); } JFrame frame = new JFrame(); JDesktopPane pane = new JDesktopPane(); JInternalFrame if1 = new JInternalFrame("IF1"); JInternalFrame if2 = new JInternalFrame("IF2"); if1.setTitle("IF1"); if2.setTitle("IF2"); pane.add(if1); pane.add(if2); frame.getContentPane().add(pane); frame.setSize(500, 500); frame.setVisible(true); if1.setMaximizable(true); if1.setSize(400, 400); showInternalFrame(if1); if1.addInternalFrameListener(new MyInternalFrameListener("IF1")); if2.setMaximizable(true); if2.setSize(300, 300); if2.setVisible(true); showInternalFrame(if2); if2.addInternalFrameListener(new MyInternalFrameListener("IF2")); System.out.println("------------------------------"); try { if1.setMaximum(true); } catch (PropertyVetoException e) { e.printStackTrace(); } System.out.println("--------------------------------"); showInternalFrame(if2); } static class MyInternalFrameListener extends InternalFrameAdapter { String name; public MyInternalFrameListener(String name) { this.name = name; } @Override public void internalFrameActivated(InternalFrameEvent e) { System.out.println(name + " activated"); } @Override public void internalFrameIconified(InternalFrameEvent e) { System.out.println(name + " iconfied"); } @Override public void internalFrameDeactivated(InternalFrameEvent e) { System.out.println(name + " deactivated"); } @Override public void internalFrameDeiconified(InternalFrameEvent e) { System.out.println(name + " deiconfied"); } } public static void showInternalFrame(JInternalFrame intf) { try { if (intf.isIcon()) intf.setIcon(false); intf.setVisible(true); intf.moveToFront(); intf.setSelected(true); } catch (PropertyVetoException ex) { ex.printStackTrace(); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload