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

JScrollPane fails to display the background behind a transparent image

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.3.0
    • Fix Version/s: None
    • Component/s: client-libs

      Description

      As demontrated in the following program, the JButton (1st component), the
      JLabel (2nd) component are transparent. However, the 3rd component which
      is a transparent image is completely opaque, blocking out its rainy
      background.

      Regress the same program with jdk1.2 and that 3rd component is displayed
      as transparent.

      In order for this program to work, it also needs the 4 attached GIF files,
      2 of which have transparent background.

      This bug could be related to bug #4313754

      Roger Pham 2/22/2000

      ----------------------------------------------------------------------

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

      public class Test extends JFrame {
          public static void main(String argv[]) {
              Test test = new Test();
              test.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent we) {
                      System.exit(0);
                  }
              });
              test.pack();
              test.setSize(900, 900);
              test.setVisible(true);
          }

          Test() {
      Container contentPane = new CustomContentPane();
      JLabel view1 = new JLabel(new ImageIcon("gjMedium.gif"));
      JLabel view2 = new JLabel(new ImageIcon("anjinAndMariko.gif"));
      JLabel view3 = new JLabel(new ImageIcon("gjLarge.gif"));
      JButton button = new JButton("Push me!");


      JScrollPane sp1 = new JScrollPane(view1);
      JScrollPane sp2 = new JScrollPane(view2);

      setContentPane(contentPane);
      sp1.setPreferredSize(new Dimension(250,250));
      sp2.setPreferredSize(new Dimension(250,250));

      contentPane.add(button);
      contentPane.add(view3);
      contentPane.add(sp1);
      contentPane.add(sp2);

      // explicitly set everything to be transparent, although this may not be necessary
      button.setOpaque(false);
      view1.setOpaque(false);
      view2.setOpaque(false);
      view3.setOpaque(false);
      sp1.setOpaque(false);
      sp2.setOpaque(false);
      ((JPanel) contentPane).setOpaque(false);

          }
      }
      class CustomContentPane extends JPanel {
          private ImageIcon rain = new ImageIcon("rain.gif");

          public CustomContentPane() {
      setLayout(new FlowLayout());
          }
          public void paintComponent(Graphics g) {
      int rainw = rain.getIconWidth();
      int rainh = rain.getIconHeight();

      Dimension size = getSize();

      for(int row=0; row < size.height; row += rainh)
      for(int col=0; col < size.width; col += rainw)
      rain.paintIcon(this,g,col,row);
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              svioletsunw Scott Violet (Inactive)
              Reporter:
              rphamsunw Roger Pham (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: