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

Swing JButton with icon not painted

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 7
    • client-libs
    • 2d
    • x86
    • windows_vista

      FULL PRODUCT VERSION :
      - 1.7.0-b147
      - 1.7.0_02-ea

      ADDITIONAL OS VERSION INFORMATION :
      - Windows Vista Pro SP2 64-bit French
      - Windows 7 Pro SP1 64-bit French

      A DESCRIPTION OF THE PROBLEM :
      When using an Eclipse Rich Platform application, with an EditorPart
      which displays java2D in an awt panel containing a Swing JPanel,
      the latter having a JToolbar with some buttons (just icon, no text)
      the buttons are grey and an exception is thrown.

      The behaviour is similar to the one reported in bug 6961999, it occurs with javax.swing.ImageIcon.paintIcon instead of ImageTransferGUI$TestFrame.paint, but also it was working perfectly with JRE 1.6.0_23.


      REGRESSION. Last worked in version 6u26

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create an eclipse plugin with one editor

      The editor shall use an SWT_AWT.new_Frame() frame,
      the frame welcomes a java.awt.Panel,
      the panel a javax.swing.JPanel,
      the jpanel a javax.swing.JToolbar
      the toolbar a JButton(javax.swing.Icon)

      run the RCP and edit a file with the editor: the buttons are not painted.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The icons should be painted, as with JRE 1.6.0.
      ACTUAL -
      The specified exception is thrown
      The icons stay grey, they are painted only when the mouse passes over.



      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: [S cannot be cast to [I
      at java.awt.image.DirectColorModel.getRGB(Unknown Source)
      at sun.java2d.loops.OpaqueCopyAnyToArgb.Blit(Unknown Source)
      at sun.java2d.loops.GraphicsPrimitive.convertFrom(Unknown Source)
      at sun.java2d.loops.GraphicsPrimitive.convertFrom(Unknown Source)
      at sun.java2d.loops.MaskBlit$General.MaskBlit(Unknown Source)
      at sun.java2d.loops.Blit$GeneralMaskBlit.Blit(Unknown Source)
      at sun.java2d.pipe.DrawImage.blitSurfaceData(Unknown Source)
      at sun.java2d.pipe.DrawImage.renderImageCopy(Unknown Source)
      at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
      at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
      at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
      at sun.awt.image.ImageRepresentation.drawToBufImage(Unknown Source)
      at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
      at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
      at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
      at javax.swing.ImageIcon.paintIcon(Unknown Source)
      at javax.swing.plaf.basic.BasicButtonUI.paintIcon(Unknown Source)
      at javax.swing.plaf.basic.BasicButtonUI.paint(Unknown Source)
      at javax.swing.plaf.ComponentUI.update(Unknown Source)
      at javax.swing.plaf.metal.MetalButtonUI.update(Unknown Source)
      at javax.swing.JComponent.paintComponent(Unknown Source)
      at javax.swing.JComponent.paint(Unknown Source)
      at javax.swing.JComponent.paintChildren(Unknown Source)
      at javax.swing.JComponent.paint(Unknown Source)
      at javax.swing.JComponent.paintChildren(Unknown Source)
      at javax.swing.JComponent.paint(Unknown Source)
      at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
      at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
      at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
      at java.awt.Container.paint(Unknown Source)
      at sun.awt.RepaintArea.paintComponent(Unknown Source)
      at sun.awt.RepaintArea.paint(Unknown Source)
      at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
      at java.awt.Component.dispatchEventImpl(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$000(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package test2;

      import java.awt.BorderLayout;
      import java.awt.Frame;
      import java.awt.Panel;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.net.URL;

      import javax.swing.Icon;
      import javax.swing.ImageIcon;
      import javax.swing.JButton;
      import javax.swing.JPanel;
      import javax.swing.JToolBar;

      import org.eclipse.core.runtime.IProgressMonitor;
      import org.eclipse.swt.SWT;
      import org.eclipse.swt.awt.SWT_AWT;
      import org.eclipse.swt.layout.FillLayout;
      import org.eclipse.swt.widgets.Composite;
      import org.eclipse.ui.IEditorInput;
      import org.eclipse.ui.IEditorSite;
      import org.eclipse.ui.PartInitException;
      import org.eclipse.ui.part.EditorPart;

      public class Editor extends EditorPart {
      JButton btnNewButton;

      public Editor() {
      // TODO Auto-generated constructor stub
      }

      @Override
      public void doSave(IProgressMonitor monitor) {
      // TODO Auto-generated method stub

      }

      @Override
      public void doSaveAs() {
      // TODO Auto-generated method stub

      }

      @Override
      public void init(IEditorSite site, IEditorInput input)
      throws PartInitException {
      this.setSite(site);
      this.setInput(input);
      this.setPartName(input.getName());

      }

      @Override
      public boolean isDirty() {
      // TODO Auto-generated method stub
      return false;
      }

      @Override
      public boolean isSaveAsAllowed() {
      // TODO Auto-generated method stub
      return false;
      }

      @Override
      public void createPartControl(Composite parent) {
      Composite top = new Composite(parent, SWT.EMBEDDED);
      FillLayout layout = new FillLayout();
      top.setLayout(layout);

      // Embed an AWT frame
      Frame frame = SWT_AWT.new_Frame(top);
      frame.setLayout(new BorderLayout());

      Panel panel = new Panel();
      frame.add(panel);
      panel.setLayout(new BorderLayout(0, 0));

      JPanel rootPane = new JPanel();
      panel.add(rootPane);
      URL url = getClass().getResource("Search.png");
      final Icon search = new ImageIcon(url);

      JToolBar toolBar = new JToolBar();
      rootPane.add(toolBar, BorderLayout.NORTH);
      btnNewButton = new JButton(search);
      toolBar.add(btnNewButton);
      btnNewButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
      System.out.println("Button Pressed");
      }
      });

      }

      @Override
      public void setFocus() {
      btnNewButton.paint(btnNewButton.getGraphics());
      }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      use JRE 1.6.0_23 instead of JRE 1.7.0

            bae Andrew Brygin
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: