Java在JFrame上圆角? [英] Java rounded corners on JFrame?

查看:191
本文介绍了Java在JFrame上圆角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个登录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);

这篇关于Java在JFrame上圆角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆