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

PNG with transparent background doesn't render correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 6
    • client-libs
    • 2d
    • b77
    • x86
    • windows_xp

      /*

      If you run this app with the attached PNG image ("test.png") in
      the same directory you'll see that the lightbulb image's background
      is white - not transparent. However viewing the same image with
      Microsoft's tools shows that the image has a transparent background.
      As well it should, since it was saved that way using IrFanView 3.98,
      a freeware image editor.

      */

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

      public class Test {
         JFrame mainFrame = null;

         void initialize(String[] ignore) {
             Icon icon = new ImageIcon("test.png");
             mainFrame = new JFrame("Image should have transparent background");
             Container cp = mainFrame.getContentPane();
             cp.setBackground(Color.green);
             mainFrame.add(new JLabel(icon));
         }

         void show() {
             mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             mainFrame.pack();
             mainFrame.setVisible(true);
         }

         public static void main(final String[] args) throws Exception {
             Runnable doCreateAndShowGUI = new Runnable() {
                 public void run() {
                     try {
                         Test app = new Test();
                         app.initialize(args);
                         app.show();
                     }
                     catch (Exception e) {
                         // TBD log an error
                     }
                 }
             };
             SwingUtilities.invokeLater(doCreateAndShowGUI);
         }
      }

            bae Andrew Brygin
            svioletsunw Scott Violet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: