Create Rounded Borders in Swing



Let us first create a Frame:

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setUndecorated(true);

Now, create rounded borders:

double x = 50;
double y = 50;

frame.setShape(new RoundRectangle2D.Double(x, y, 100, 100, 50, 50));

The following is an example to create rounded borders in Swing:

Example

import java.awt.geom.RoundRectangle2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class SwingDemo extends JPanel {
   public static void main(String[] args) {
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setUndecorated(true);
      double x = 50;
      double y = 50;
      frame.setShape(new RoundRectangle2D.Double(x, y, 100, 100, 50, 50));
      frame.setSize(600, 500);
      frame.setLocationByPlatform(true);
      frame.setVisible(true);
   }
}

Output

Updated on: 2019-07-30T22:30:26+05:30

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements