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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Buttons like Netbeans'

843806Jan 15 2008 — edited Jan 15 2008
Hi,

The buttons in NetBeans' toolbar, for example, don't have their content area filled. However, when rolling the mouse over them, the border is painted.
What are the properties needed to be enabled/disabled in order to acheive this effect? I've tried a bunch of them but without success.

Thank you.

Comments

843806
Try this out

http://java.sun.com/javase/6/docs/api/javax/swing/JToolBar.html#setRollover(boolean)
843806
That's exactly the behavior I want. However, my buttons don't belong to a JToolBar...
843806
Then this is waht you want
btn.setBorderPainted(false);
btn.setMargin(new Insets(0,0,0,0));
btn.addMouseListener(new MouseAdapter()
{
	public void mouseEntered(MouseEvent me)
	{
		btn.setBorderPainted(true);
	}
			
	public void mouseExited(MouseEvent me)
	{
		btn.setBorderPainted(false);
	}
});
843806
That didn't do it.

Is there any chance the Look&Feel is messing with it? I'm using the Windows L&F on Windows XP.

UPADTE:

For now, I've decided to put my buttons in a JToolBar but there's another issue: the last clicked button keeps the "rollover" state, thus painting the border.
I hope you know what I mean.

Edited by: Alexin on Jan 15, 2008 7:42 AM
camickr
That didn't do it. Is there any chance the Look&Feel is messing with it? I'm using the Windows L&F on Windows XP.
Works fine for me using JDK1.4.2 on XP.
the last clicked button keeps the "rollover" state, thus painting the border. I hope you know what I mean.
No I don't know what you mean. Same comment as above.

If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
http://homepage1.nifty.com/algafield/sscce.html

Don't forget to use the "Code Formatting Tags", so the posted code retains its original formatting.
http://forum.java.sun.com/help.jspa?sec=formatting
843806
minor correction to my previous code
btn.setBorderPainted(false);
btn.setContentAreaFilled(false);
btn.setFocusPainted(false);	
btn.setMargin(new Insets(0,0,0,0));
btn.addMouseListener(new MouseAdapter()
{
	public void mouseEntered(MouseEvent me)
	{
		btn.setBorderPainted(true);
		btn.setContentAreaFilled(true);
	}
			
	public void mouseExited(MouseEvent me)
	{
		btn.setBorderPainted(false);
		btn.setContentAreaFilled(false);
	}
});
Edited by: Yezdi on Jan 15, 2008 8:49 AM
1 - 6
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Feb 12 2008
Added on Jan 15 2008
6 comments
306 views