Search code examples
javaswingborderjlabelpaintcomponent

How to make 3D rounded corner JLabel in Java?


I know there is a way to extend a JLabel to paint 3D borders and a way to paint round borders, but how do you get both? Here is my code

protected void paintComponent(Graphics g) {
     g.setColor(getBackground());
     g.fillRoundRect(0, 0, getWidth()-1, getHeight()-1, 25, 25);
     g.fill3DRect(10, 10, 30, 30, true);
     super.paintComponent(g);

Solution

  • Use LineBorder with rounded corners or a variant of the TextBubbleBorder.