I have a login JFrame for my application and i would like to make the corners of the frame rounded by a few pixles.
Id like to do this without using transparency on the JFrame and having to use a background image inside a JPanel - is this possible?
It's possible with undecorated frame, consider the following example:
JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.setShape(new RoundRectangle2D.Double(10, 10, 100, 100, 50, 50));
frame.setSize(300, 200);
frame.setVisible(true);
This code works on Java 7. For Java 6 (since update 10) you can do the same with AWTUtilities.setWindowShape
:
JFrame frame = new JFrame();
frame.setUndecorated(true);
AWTUtilities.setWindowShape(frame, new RoundRectangle2D.Double(10, 10, 100, 100, 50, 50));
frame.setSize(300, 200);
frame.setVisible(true);
Try this. It works :)
yourframe.setUndecorated(true);
yourframe.setBackground(new Color(0, 0, 0, 180));
yourframe.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
setShape(new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 80, 80));
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With