Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undecorated non-opaque JDialog glitches whenever its parent JFrame is minimized and restored #466

Open
mgarin opened this issue Sep 8, 2017 · 5 comments

Comments

@mgarin
Copy link
Owner

mgarin commented Sep 8, 2017

Whenever undecorated non-opaque JDialog parent JFrame is minimized and restored - that JDialog glitches visually (doesn't display anything properly anymore).

I noticed this bug first time in the demo application on WebDockableFrames - they have the very same issue as they use WebDialog to display floating frame state.

Here is an SSCCE:

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TransparentDialogTest
{
    public static void main ( final String[] args )
    {
        final JFrame frame = new JFrame ( "Dialog test frame" );
        final JButton button = new JButton ( "Show dialog" );
        frame.add ( button );
        frame.setDefaultCloseOperation ( WindowConstants.EXIT_ON_CLOSE );
        frame.pack ();
        frame.setLocationRelativeTo ( null );

        final JDialog dialog = new JDialog ( frame, "Sample dialog" );
        final JLabel label = new JLabel ( "Sample dialog content" )
        {
            protected void paintComponent ( Graphics g )
            {
                g.setColor ( Color.RED );
                g.fillOval ( 0, 0, getWidth (), getHeight () );

                super.paintComponent ( g );
            }
        };
        label.setBorder ( BorderFactory.createEmptyBorder ( 50, 50, 50, 50 ) );
        dialog.add ( label );
        dialog.setUndecorated ( true );
        dialog.setBackground ( new Color ( 255, 255, 255, 0 ) );
        dialog.pack ();

        button.addActionListener ( new ActionListener ()
        {
            public void actionPerformed ( ActionEvent e )
            {
                final Dimension size = dialog.getSize ();
                final Point los = button.getLocationOnScreen ();
                dialog.setLocation ( los.x + button.getWidth () / 2 - size.width / 2, los.y + button.getHeight () );
                dialog.setVisible ( true );
            }
        } );

        frame.setVisible ( true );
    }
}

To reproduce it:

  1. Run it
  2. Click button to open dialog
  3. Minimize frame
  4. Restore frame

Result:
Dialog is glitched/invisible (depends on OS/JDK version).

JDK bug reference:
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8187603

It only reproduces on Windows OS and only with JDK 7 and later. There is a possible workaround and I will try to add it to avoid this issue in WebLaF in general, but I have already submitted JDK bugreport, hopefully it will get fixed in one of the later JDK updates.

@mgarin mgarin added this to the JDK related milestone Sep 8, 2017
@mgarin mgarin self-assigned this Sep 8, 2017
@mgarin
Copy link
Owner Author

mgarin commented Sep 8, 2017

This issue doesn't really have anything to do with WebLaF (as you can see example is pure Swing), but it does make some of WebLaF features unusable in specific cases, so I will try to provide an appropriate fix for this, especially considering the possibility of actual fix only coming in JDK 9.

@mgarin
Copy link
Owner Author

mgarin commented Sep 18, 2017

This bug was officially confirmed and accepted as JDK bug:
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8187603

@mgarin
Copy link
Owner Author

mgarin commented Oct 10, 2017

Unfortunately official resolution is: Won't Fix

Quote:

Closing - Won't Fix (For JDK 7 & 8)
Please utilize the solution with JDK 9, or raise a customer support case.

I guess another reason to move straight up to JDK 9 when I will be jumping to WebLaF 2.x development. Also I'm not yet sure if I will add any workaround for this problem in WebLaF or not, will have to test possible solutions on how reliable they are.

@mgarin mgarin removed the JDK 9 label Oct 10, 2017
@mgarin
Copy link
Owner Author

mgarin commented Oct 10, 2017

So right now this only appears on JDK 7 and 8.
It is working properly on JDK 6 and 9.

@mgarin
Copy link
Owner Author

mgarin commented Oct 10, 2017

I will soon look into #452 to fix various issues which appeared in JDK 9, so that should help for those who are ready to move to newer JDK versions to avoid issues like this one.

@mgarin mgarin removed this from the JDK related milestone Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant