JDK-8147840 : The AeroSnap state of a is lost by minimizing with frame.setExtendedState()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u66,9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2016-01-18
  • Updated: 2016-04-20
  • Resolved: 2016-04-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
If a frame which was snapped to left (or right) edge of the Screen is minimized by calling setExtendedState() it loses it's "snapped-state". 
The Windows-Taskbar preview shows the before-snapped position and size. If the frame is unminimized it will be restored at this wrong location. 

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Start "AeroSnapAndMinimize.java".
2. Move the frame to the left edge of the screen to aero-snap it.
3. Click the JButton labeled "Minimize".
4. Hover above the program-symbol in the taskbar to see the wrong preview.
5. Click the program-symbol in the taskbar to show the frame at the old, wrong position (and with the old size). 

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The frame should be restored correctly snapped. And when dragged away from the edge the old (before snap) size should be restored.
ACTUAL -
The frame gets restored at the old (before snap) position and with the old size.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package frame.state;

import java.awt.FlowLayout;
import java.awt.Frame;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class AeroSnapAndMinimize extends JFrame
{

  public AeroSnapAndMinimize( final String title )
  {
    super( title );
    initUI();
  }

  private void initUI()
  {
    setDefaultCloseOperation( EXIT_ON_CLOSE );
    setLayout( new FlowLayout() );
    final JButton minimize = new JButton( "Minimize" );
    add( minimize );
    pack();

    minimize.addActionListener( e ->
    {
      setExtendedState( getExtendedState() | Frame.ICONIFIED );
    } );
  }

  public static void main( final String[] args )
  {
    SwingUtilities.invokeLater( () -> new AeroSnapAndMinimize( "AeroSnap and minimize" ).setVisible( true ) );
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Three Workarounds are possible: 

1. Remember the position and size and restore it when the frame is unminimized. Result: a wrong preview position and size.

2. setVisible(false) before and setVisible(true) after minimizing. Result: no preview-content for the frame.

3. Use a native (JNA) windows-call "User32.INSTANCE.CloseWindow( windowHandle )". Result: works as expected.

See StackOverflow (http://stackoverflow.com/questions/34638183/is-this-the-only-way-to-teach-a-java-frame-something-about-the-aero-snap-feature) for more Information.