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

查看:24
本文介绍了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);

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

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