创建圆形 JFrame / ContentPane

发布于 2024-07-22 21:14:09 字数 315 浏览 1 评论 0原文

我正在用java创建一个带有圆角的登录窗口。 一切都很好,参见图片,但我在使 JFrame / ContentPane 透明时遇到了挑战。 每个角都有白色区域(如箭头所示),我似乎无法删除它们,因为我无法将 JFrame 或 ContentPane 的 opague 设置为 false。

关于如何去除这些白色区域的任何想法 替代文本

I'm creating a login window with rounded corners in java. Everything is OK, see pic, but i'm having challenges making the JFrame / ContentPane transparent. There are white areas at each corner (shown by the arrows) that i seem not to be able to remove since i can't set opague to false for the JFrame or ContentPane.

Any ideas of how i can remove these white areas
alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

与往事干杯 2024-07-29 21:14:09

从 Java 1.3 开始,有一个技巧可以让窗口部分透明,或者窗口淡入(我通常将其用于启动画面),或者特殊的 FX(例如阴影):

  • 在打开窗口之前,以编程方式截取该区域的屏幕截图您的窗口所在的位置(使用 java.awt.Robot.createScreenCapture())
  • 将屏幕截图设置为根容器的背景(具有自定义 PaintComponent() 例程的 JPanel)
  • 现在您可以添加各种透明组件,或绘制背景顶部的另一个半透明图像。

使用此技术创建带有半透明阴影的窗口的示例:
http://www.eclipsezone.com/eclipse/forums/t17720.html

Since Java 1.3 there's a trick which allows to make partially transparent windows, or windows fading in (I usually use this for my splash screens), or special FX (such as shadows):

  • Before opening the window, programmatically take a screenshot of the region where your window is going to be (using java.awt.Robot.createScreenCapture())
  • Set the screenshot as the background of your root container (JPanel with custom paintComponent() routine)
  • Now you can add all kinds of transparent components, or paint another semitransparent image on top of the background.

Example which creates a window with a semitransparent shadow using this technique:
http://www.eclipsezone.com/eclipse/forums/t17720.html

青瓷清茶倾城歌 2024-07-29 21:14:09

对您没有太大帮助,但 Java7 将支持透明和形状的窗口:更多信息此处 。 这些已经在 J​​ava 6u10 中提供,但不是公开的,即,您需要使用不受支持的 com.sun... 类,该类将来可能会发生变化并破坏您的程序。

Not much help to you but Java7 will support transparent and shaped windows: More info here. These are available already in Java 6u10 but not publicly, ie, you need to use an unsupported com.sun... class that might change in future and break your program.

祁梦 2024-07-29 21:14:09

尝试这个。 是工作 :)

yourframe.setBackground(new Color(0, 0, 0, 180));
yourframe.setUndecorated(true);
yourframe.addComponentListener(new ComponentAdapter() {
               @Override
                public void componentResized(ComponentEvent e) {
                    setShape(new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 80, 80));
                }
            });

try this. its work :)

yourframe.setBackground(new Color(0, 0, 0, 180));
yourframe.setUndecorated(true);
yourframe.addComponentListener(new ComponentAdapter() {
               @Override
                public void componentResized(ComponentEvent e) {
                    setShape(new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 80, 80));
                }
            });
断念 2024-07-29 21:14:09

JFrame 无法透明,因为它是重量级组件。 只有像 JWindow 这样的轻量级组件才能变得透明。

JFrame can not be made transparent as it is a heavyweight component. Only lightweight components such as JWindow can be made transparent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文