Java Program to create rounded borders in Swing

Java 8Object Oriented ProgrammingProgramming

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

raja
Published on 03-May-2019 07:45:07
Advertisements