2

As the title states I have a JDialog with invisible but clickable components. See SSCCE below. This behaves correctly (i.e. the "close me" button is visible) on Windows with oracle jdk1.8.0_201. The problem is reproducible on Debian 10 with openbox using oracle jdk1.8.0_201.

When the problem occurs the JDialog shows up but is completely gray. The button is clickable though and does close the dialog as expected.

The problem seems to go away when I don't set the type to "POPUP" and gets less likely to occur (varying occurrence rates) with other modifications commented in the sample code. I would like to keep the type POPUP because setting it solved other problems that were tricky to get rid of in the context of the real application.

What am I doing wrong?

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;

public class LockPane extends JDialog {

    public LockPane(JFrame parentFrame, JPanel componentToShow, Dimension paneSize) {
        super(parentFrame, true);
        setType(Type.POPUP);  // removing this seems to fix the issue. but why?
        setUndecorated(true); // removing this seems to make the issue less likely to occur but does not fix it completely
        setSize(paneSize);    // removing this seems to make the issue less likely to occur but does not fix it completely
        setPreferredSize(paneSize);
        setMaximumSize(paneSize);   // removing this seems to make the issue less likely to occur but does not fix it completely
        setLayout(new GridLayout(1, 1));
        add(componentToShow);
        setAlwaysOnTop(true);
        pack();
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("Lockpane Demo");
        frame.setLayout(new BorderLayout());
        JButton button = new JButton("click me to demonstrate the problem");
        button.setPreferredSize(new Dimension(400, 400));
        frame.add(button);
        frame.pack();
        button.addActionListener(e -> {
            JButton closeButton = new JButton("Close me");
            JPanel componentToShow = new JPanel(new BorderLayout());
            componentToShow.setSize(new Dimension(200, 200));
            LockPane lockPane = new LockPane(frame, componentToShow, new Dimension(200, 200));
            componentToShow.add(closeButton, BorderLayout.CENTER);
            lockPane.add(componentToShow);
            closeButton.addActionListener(e1 -> {
                System.out.println("lock pane button was clicked");
                lockPane.setVisible(false);
            });
            lockPane.setVisible(true);
        });
        frame.setVisible(true);
    }
}

EDIT: I tested this with openjdk-11 - not reproducible there! I then tested with the adoptopenjdk jdk8u242-b08 and the problem occurred again. Could this actually be a Bug in Java 8?

EDIT2: I tested this with adoptopenjdk jdk8u242-b08 on Debian 10 with a Cinnamon Desktop. Same problem. So I don't think it's desktop related.

EDIT3: I am giving up. I will do without the Window Type Popup. I'd still be interested if anyone found a solution to this.

edr
  • 436
  • 3
  • 5
  • 15
  • If you're using Linux, then this issue is possibly caused by the `xf86-video-intel` video driver package, and can possibly be worked around by installing more modern drivers: https://www.reddit.com/r/filebot/comments/ggzsqs/filebot_wont_show_me_ui_text_in_menus_linux/ – rednoah May 13 '20 at 06:49
  • Hmm, this does look similar. However, I am on Debian here and there is no package called xf86-video-intel. I removed xserver-xorg-video-intel - not sure if this is the exact equivalent. It did not help... – edr May 15 '20 at 07:37

0 Answers0