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

1.4 REGRESSION: Swing Transparency Problem-user defined ColorUIResource getRGB()

XMLWordPrintable

      Name: gm110360 Date: 08/22/2002


      FULL PRODUCT VERSION :
      Using 2 versions:

      java version "1.3.1_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_02-b02)
      Java HotSpot(TM) Client VM (build 1.3.1_02-b02, mixed mode)

      java version "1.4.1-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
      Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Windows 2000
      5.00.2195
      Service Pack 2

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Video Card:
      ASIC Type: Radeon VE
      ASIC ID: 5159
      Bus Type: AGP1,2,4X

      Memory Size: 32M
      Memory Type: DDR SGRAM / SDRAM

      A DESCRIPTION OF THE PROBLEM :
      My goal was to create a JMenuItem that was transparent. I
      ran a code example that displayed a transparent JMenuItem
      over an image. However, when you moved

      the mouse up and down the selection list of the menu, the
      rollover would occur (highlight and unhighlight) and
      trigger a repaint. The repaint is where the

      problem is, as the items would repaint incorrectly, and
      transparency was lost once you rolled over an item. The
      repaint would paint over top of the last

      image in the buffer, so the more rolloevers you did, the
      darker the image got, until transparency was lost
      completely. The important point here is that I ran

      this using JDK1.3.1_02.

      Well, I tried to go to JDK1.4, in the hopes of it being
      fixed. However, with 1.4 there is no transparency showing
      up whatsoever, and the menu item is acting

      as if I specified a default menu item.

      So, I went and downloaded a professional product, hoping it
      was a code problem, or maybe I might find a workaround. So
      I checked out the "Skin Look and

      Feel". If you run the Skin demo with Java 1.3, their menus
      appear transparent, and animate from 0% opacity, to approx
      75% opacity, and stay transparent.

      Everything worked perfectly. So I assume it was my code,
      which I'm going to look into. However, if you run this demo
      in 1.4, there is no transparency, thus

      there is no animation either. Here is the info for the skin
      demo:

        Company: L2FProd.com
      Product: SkinLF 1.2.2
      URL: http://www.l2fprod.com/
      Click on WebStart Demo to launch

      In conclusion, my problem is this: Sun says 1.3 apps will
      work on 1.4, but they don't. I realize Java 2D has
      undergone some serious changes. But is there a

      workaround for this particular problem? Is this a known
      problem? If so, when will it be fixed?


      REGRESSION. Last worked in version 1.3.1

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. compile all classes in default package
      2. run ThemeTest
      3. rollovers menu items with mouse

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      transparency display/repaint problems

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Note: To run properly, you need to get a JPG, and JPG file at least 200x200
      pixels or so, and call it "sample.jpg", and leave it in the default directory
      where the classes are.

      There are 3 classes:



      ThemeTest.java

      import java.awt.event.ItemEvent;
      import java.awt.event.ItemListener;
      import javax.swing.ImageIcon;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;

      public class ThemeTest extends JFrame implements ItemListener {
        JMenu menu = null;
        JMenuItem item1 = null;
        JMenuItem item2 = null;
        JMenuItem item3 = null;

        ThemeTest() {
          menu = new JMenu("MENU");
          item1 = new JMenuItem("Item 1");
          item2 = new JMenuItem("Item 2");
          item3 = new JMenuItem("Item 3");
          menu.add(item1);
          menu.add(item2);
          menu.add(item3);
          menu.addItemListener(this);
          JMenuBar bar = new JMenuBar(); bar.add(menu);
          setJMenuBar(bar);
          JLabel label = new JLabel(new ImageIcon("sample.jpg"));
          getContentPane().add(label);
          this.setSize(250, 250);
        }

        public static void main(String[] args) {
          TransparentTheme.install(); new ThemeTest().show();
        }

        public void itemStateChanged(ItemEvent e) {
          System.out.println("action");
        }
      }




      TransparentTheme.java

      import javax.swing.UIManager;
      import javax.swing.plaf.ColorUIResource;
      import javax.swing.plaf.metal.DefaultMetalTheme;
      import javax.swing.plaf.metal.MetalLookAndFeel;

      public class TransparentTheme extends DefaultMetalTheme {
        public ColorUIResource getMenuBackground() {
          return getT(super.getMenuBackground());
        }

        public ColorUIResource getMenuSelectedBackground() {
          return getT(super.getMenuSelectedBackground());
        }

        private static ColorUIResource getT(ColorUIResource c) {
          return new TransparentColorUIResource(c);
        }

        public static void install() {
          MetalLookAndFeel.setCurrentTheme(new TransparentTheme());
          try {
            UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
          }
          catch (Exception ex) {
            System.out.println("Failed loading Metal");
            System.out.println(ex);
          }
        }
      }




      TransparentColorUIResource.java

      import java.awt.Color;
      import javax.swing.plaf.ColorUIResource;

      public class TransparentColorUIResource extends ColorUIResource {
        private static int MASK = 0x66ffffff;
        private int r, g, b;
        int rgba32;

        public TransparentColorUIResource(Color c) {
          super(c);
          // This is a nasty hack, but ColorUIResource has no transparency
          // option in the constructor
          r = c.getRed();
          g = c.getGreen();
          b = c.getBlue();
        }

        public int getRGB() {
          rgba32 = (0x11ffffff | (r << 16) | (g << 8) | b);
          return rgba32;
        }
      }

      ---------- END SOURCE ----------

      Release Regression From : hopper-rc
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

      (Review ID: 159564)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: