Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7510489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:14:04+00:00 2026-05-29T23:14:04+00:00

Has anyone tried to style JButton to look like NetBeans toolbar buttons? That would

  • 0

Has anyone tried to style JButton to look like NetBeans toolbar buttons? That would be showing just a picture and when you hover over it, a 1px rounded correner gray border shows and a background different on top and on the bottom of the button… Can’t seem to be able to style a JButton like that…. any suggestions? Thanks!

enter image description here
Left: normal
Middle: hover
Right: focus

I don’t even need that half-half background really, just can’t even get borders to paint on hover…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:14:05+00:00Added an answer on May 29, 2026 at 11:14 pm

    How about this implementation? I reference another question and added a small green triangle called netbeans.png where I found from the google. However, there is a small TODO part for you 😉 where to paint the border with a different background once the button get the focus. I hope you like this answer.

    import java.awt.Color;
    import java.awt.FlowLayout;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.Shape;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.geom.Area;
    import java.awt.geom.RoundRectangle2D;
    import java.net.URL;
    
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    
    public class StylistButton extends JButton implements MouseListener
    {
        boolean mouseIn = false;
    
        public StylistButton(String s)
        {
            addMouseListener(this);
            setBorderPainted(false);
            setContentAreaFilled(false);        
        }
    
        protected static ImageIcon createImageIcon(String path)
        {
            URL imgURL = TextSamplerDemo.class.getResource(path);
            if (imgURL != null)
            {
                return new ImageIcon(imgURL);
            }
            else
            {
                System.err.println("Couldn't find file: " + path);
                return null;
            }
        }   
    
    
        protected void paintComponent(Graphics g)
        {
            // set button big enough so we can see the rounding curve.
            setSize(60, 40);
            ImageIcon netbeans = createImageIcon("netbeans.png");
    
            if (netbeans != null)
            {
                setIcon(netbeans);
            }
    
            setIcon(netbeans);
            Color[] gradients;
            Graphics2D g2 = (Graphics2D) g;
            super.paintComponent(g2);
    
            if(getModel().isRollover())
            {
                g2.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
                Shape firstClip = g.getClip();
                RoundRectangle2D rect = new RoundRectangle2D.Double();
                double arc = Math.ceil(getSize().getHeight() / 3);
                rect.setRoundRect(0, 0, Math.ceil(getSize().getWidth()), Math.ceil(getSize().getHeight()), arc, arc);
                Area secondClip = new Area(getBounds());
                secondClip.subtract(new Area(rect));
                Area finalClip = new Area(firstClip);
                finalClip.subtract(secondClip);
                g2.setClip(finalClip);
                super.paintComponent(g2);           
    
                gradients = new Color[] { new Color(184, 207, 229), new Color(122, 138, 153), new Color(184, 207, 229) };
    
                for(int i = 0; i < gradients.length; i++)
                {
                    arc -= 2;
                    g2.setColor(gradients[i]);          
                    g2.drawRoundRect(i+1, i+1, (int)Math.ceil(getSize().getWidth()-2)-(i*2), (int)Math.ceil(getSize().getHeight()-2)-(i*2), (int)arc, (int)arc);
                }
            }
            else if (getModel().isSelected())
            {
                // TODO, leave a permanent focus mark here.
            }
        }
    
        public static void main(String[] args)
        {
            JFrame frame = new JFrame();
            frame.getContentPane().setLayout(new FlowLayout());
    
            StylistButton sButton = new StylistButton("stylistButton");
    
            frame.getContentPane().add(sButton);
    
            frame.setSize(250, 250);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
    
    
        @Override
        public void mouseClicked(MouseEvent e)
        {
    
        }
    
        @Override
        public void mousePressed(MouseEvent e)
        {
    
        }
    
        @Override
        public void mouseReleased(MouseEvent e)
        {
    
        }
    
        @Override
        public void mouseEntered(MouseEvent e)
        {
    
        }
    
        @Override
        public void mouseExited(MouseEvent e)
        {
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone successfully tried minifying AND concatenating all the jqGrid locale files so that
Has anyone tried using the NHibernate Velocity L2 cache provider against the Azure AppFabric
Has anyone tried to build an e-commerce site atop MS Dynamics, using the new
Has anyone tried to back up a SharePoint web application using forms based authentication
Has anyone tried automatic Java to C++ conversion for speed improvements? Is it a
Has anyone tried out working with the Delete and update command of SPDataSource used
Has anyone tried taking a video from the camera and then using the video
Has Anyone tried using PDF in iPad Application, using CGPDf functions. I have used
Does LINQPad work with Oracle? Has anyone tried? What do you suggest?
Has anyone ever tried sending emails using 1&1 smtp host? I tried the following?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.