Duplicate :
|
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.