JFrame上的Java圆角?
我有一个用于我的应用程序的登录 JFrame,我想让框架的角由几个像素变圆.
I have a login JFrame for my application and i would like to make the corners of the frame rounded by a few pixles.
我想在不使用 JFrame 上的透明度并且必须在 JPanel 内使用背景图像的情况下执行此操作 - 这可能吗?
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);
此代码适用于 Java 7.对于 Java 6(自更新 10),您可以使用 AWTUtilities.setWindowShape
:
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);
相关文章