I writing a gui program in java, my project kind is maven.
I want to use AWTUtilities
library to create JFrame
with rounded corners,
but when i trying to run the project, i accept the following errors:
The code snippet:
import com.sun.awt.AWTUtilities;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.geom.Area;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
public class Test extends JFrame{
private static Robot robot;
public static void main(String[] args) {
try {
robot = new Robot();
} catch (AWTException e1) {
e1.printStackTrace();
}
JFrame win = new JFrame();
win.setSize(700, 100);
JPanel panel = new JPanel();
JButton button = new JButton("simulate");
final JTextField textField = new JTextField();
textField.setPreferredSize(new Dimension(600, 30));
panel.add(textField);
panel.add(button);
win.add(panel);
Shape shape = new Rectangle2D.Double(0, 0, win.getWidth(), win.getHeight());
AWTUtilities.setWindowShape(win, shape);
win.setVisible(true);
}
}
How can i resolve it?
The code you wrote works only in Java 6 and under certain conditions. If you are using Java 8 and you want to create a Frame with rounded corners, try something like this:
JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.setBackground(new Color(0, 0, 0, 180));
frame.setShape(new RoundRectangle2D.Double(0, 0, 500, 600, 80, 80));