Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JButton's hover image is flashing?

843805Oct 21 2006 — edited Oct 22 2006
I'm running into a odd problem. I create a JButton by calling the following function.
public JButton createbutton(String name,String toolTip){
	
	String imagePath="images/"+name+".png";
	ImageIcon iconOver=new ImageIcon(imagePath);
	
	
	//set the cursor for the button
	Cursor cursor=Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
	
	//now to make the pressed image
	String imagepressedPath="images/"+name+"pressed.png";
	ImageIcon pressed=new ImageIcon(imagepressedPath);
	String imagehoverPath="images/"+name+"hover.png";
	ImageIcon hover=new ImageIcon(imagehoverPath);
	
	JButton button=new JButton();
	button.addActionListener(new leActionListener());
	button.setIgnoreRepaint(true);
	button.setFocusable(false);
	button.setToolTipText(toolTip);
	button.setBorder(null);
	button.setContentAreaFilled(false);
	button.setCursor(cursor);
	button.setIcon(iconOver);
	button.setRolloverIcon(hover);
	button.setPressedIcon(pressed);
	
	return button;
	
}
Then I add it to a JPanel
JButton savebutton=createbutton("saveicon","Save");

	buttonPanel=new JPanel(new FlowLayout(FlowLayout.CENTER,15,(screen.getHeight()/4)/4));
	buttonPanel.setOpaque(true);
	buttonPanel.add(savebutton);
...
Throw that ontop of a layeredPane with 3 other JPanels and add it to the main frame
	JLayeredPane layeredPane=new JLayeredPane();
	layeredPane.setPreferredSize(new Dimension(screen.getWidth(),3*(screen.getHeight())/4));
	layeredPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
layeredPane.add(buttonPanel,new Integer(0));

frame.getContentPane().add(layeredPane);
Now when I move the mouse over the button I see the hover image tooltip but only for a second. It just flashes and doesn't stay on when I leave my mouse over the button. I'm using linux and people using windows are telling me it's flashing like a strobe light on them. Any help would be much appreciated

Also if it helps, I found out that JCheckBoxs will also flash with the check marks in them on the same layeredPane. (i.e. when I move the mouse over the check boxes the checks will appear, but only for a second and not unless I move the mouse over them. The values are correct though)

Message was edited by:
stelmate
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 19 2006
Added on Oct 21 2006
1 comment
331 views