This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,889,878 Users
  • 2,269,775 Discussions
  • 7,916,823 Comments

Discussions

Buttons like Netbeans'

843806
843806 Member Posts: 49,998
edited Jan 15, 2008 11:51AM in Swing
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
    843806 Member Posts: 49,998
    Try this out

    http://java.sun.com/javase/6/docs/api/javax/swing/JToolBar.html#setRollover(boolean)
  • 843806
    843806 Member Posts: 49,998
    That's exactly the behavior I want. However, my buttons don't belong to a JToolBar...
  • 843806
    843806 Member Posts: 49,998
    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
    843806 Member Posts: 49,998
    edited Jan 15, 2008 10:46AM
    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
    camickr Member Posts: 24,931 Silver Badge
    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
    843806 Member Posts: 49,998
    edited Jan 15, 2008 11:51AM
    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
This discussion has been closed.