JDK-7096816 : Swing JButton with icon not painted
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2011-09-30
  • Updated: 2012-03-20
  • Resolved: 2011-10-17
Related Reports
Duplicate :  
Description
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

Comments
EVALUATION Fixed as a part of fix for CR 6997116.
17-10-2011

EVALUATION It appears we have a ColorModel with transfer type of short, and a pixel represented as an array of integers is passed to its getRGB(Object) method. I'm not sure what changed such that we now have a mismatch. I don't know if the supplied test case is adequate, I'll leave that up to the engineer handling the bug.
06-10-2011