6 Replies Latest reply on Jan 15, 2008 4:51 PM by 843806

    Buttons like Netbeans'

    843806
      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.
        • 1. Re: Buttons like Netbeans'
          843806
          Try this out

          http://java.sun.com/javase/6/docs/api/javax/swing/JToolBar.html#setRollover(boolean)
          • 2. Re: Buttons like Netbeans'
            843806
            That's exactly the behavior I want. However, my buttons don't belong to a JToolBar...
            • 3. Re: Buttons like Netbeans'
              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);
                   }
              });
              • 4. Re: Buttons like Netbeans'
                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
                • 5. Re: Buttons like Netbeans'
                  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
                  • 6. Re: Buttons like Netbeans'
                    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