Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8041731

JPopupMenu items invisible on heavyweight popups on translucent windows

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 7u45, 7-pool
    • client-libs

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      If a menu is using heavyweight popups (e.g., by setLightWeightPopupEnabled(false);) and that menu is opened from a translucent window, the menu items are invisible. The menu itself appears, but it is blank until the items are redrawn by rolling the mouse over them one by one.

      Although lightweight popups are on by default, this bug also occurs if the menu popup does not fit within the bounds of the parent window, because then it has no choice but to use a heavyweight popup. There is definitely something odd going on. Please run the attached test case for a demonstration.

      This bug occurs on all look-and-feels.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.event.*;

      public class Test1 {
      public static void main(final String[] args) {
      if (!EventQueue.isDispatchThread()) {
      EventQueue.invokeLater(new Runnable() {
      public void run() {
      main(args);
      }
      });
      return;
      }

      final JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

      JMenuBar menuBar = new JMenuBar();
      final JMenu file = new JMenu("File");
      menuBar.add(file);
      final JCheckBoxMenuItem enableTransparency = new JCheckBoxMenuItem("Enable transparency");
      final JCheckBoxMenuItem enableLWPopup = new JCheckBoxMenuItem("Enable light-weight popup");
      file.add(enableTransparency);
      file.add(enableLWPopup);
      file.addSeparator();
      file.add(new JMenuItem("New"));
      file.add(new JMenuItem("Open"));
      file.add(new JMenuItem("Save"));
      file.add(new JMenuItem("Exit"));

      enableLWPopup.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      file.getPopupMenu().setLightWeightPopupEnabled(
      enableLWPopup.isSelected());
      }
      });

      enableTransparency.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      frame.dispose();
      if (enableTransparency.isSelected()) {
      frame.setUndecorated(true);
      frame.setBackground(new Color(0, 0, 255, 40));
      } else {
      frame.setBackground(null);
      frame.setUndecorated(false);
      }
      frame.setVisible(true);
      }
      });

      file.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {
      public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
      enableLWPopup.setSelected(file.getPopupMenu().isLightWeightPopupEnabled());
      enableTransparency.setSelected(!frame.isOpaque());
      }
      public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
      public void popupMenuCanceled(PopupMenuEvent e) {}
      });

      frame.setJMenuBar(menuBar);

      frame.setPreferredSize(new Dimension(300, 200));

      frame.pack();
      frame.setLocationByPlatform(true);
      frame.setVisible(true);
      }
      }
      ---------- END SOURCE ----------

            alitvinov Anton Litvinov (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: