Javafx8 Popup Transparency问题

编程入门 行业动态 更新时间:2024-10-26 17:24:07
本文介绍了Javafx8 Popup Transparency问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图将我的javafx2应用程序移植到javafx8,但是注意到Linux上带有弹出控件的一些问题.

I am trying to port my javafx2 application over to javafx8 but have noticed some issues on Linux with popup controls.

屏幕截图显示了弹出窗口周围如何有一个白框,该白框通常应该是透明的并具有阴影效果. 这仅在我的Slackware14 Linux上发生,我已经在运行于同一台计算机上的Windows VM上进行了测试,并且呈现良好.

The screenshot shows how the popup have a white box around it, which normally should be transparent and drop shadow effect. This only happens on my Slackware14 Linux, I have test on the Windows VM that runs on the same machine and it renders fine.

我认为这个问题与这些问题有关 javafx-jira.kenai/browse/RT-33709 javafx-jira.kenai/browse/RT-33750

I think the issue is related to these issues javafx-jira.kenai/browse/RT-33709 javafx-jira.kenai/browse/RT-33750

我的问题是,在解决该问题之前,有什么解决方法吗?

My question is are there any workaround until it will be fixed ?

推荐答案

问题所在

默认的JavaFX 8(modena.css)没有考虑到透明窗口功能在某些平台(特别是某些Linux平台)上是可选的.

The default JavaFX 8 (modena.css) does not take into account that the transparent window feature is optional on some platforms (specifically some Linux platforms).

在Java 9发布之前,不太可能更改默认的CSS.

It is unlikely that the default css will be changed until Java 9 comes out.

如何修复

这是仅适用于Java 8+的解决方案.

This is a solution for Java 8+ only.

提供您自己的CSS来覆盖默认的CSS,以便您可以支持那些平台,而不必在某些控件周围显示难看的白色边框区域.您提供的css可以假定透明窗口不是基础平台的功能,并且可以对UI进行样式设置,以便在此类平台上看起来仍然不错.由于透明窗口功能是ConditionalFeature,在应用程序启动时,检查查看是否支持条件功能,如果不支持,请通过 Application.setUserAgentStyleSheet().

Supply your own css to override the default css so that you can support those platforms without displaying an ugly white border areas around some of your controls. The css you provide can assume that transparent windows are not a feature of the underlying platform and style the UI so that it still looks good on such platforms. As the transparent window feature is a ConditionalFeature, on application startup, check to see if the conditional feature is supported, and if it is not, apply your custom stylesheet via Application.setUserAgentStyleSheet().

示例应用

我仅在Mac(支持透明窗口功能)上进行了测试,因此我无法真正验证它是否可以在Linux上正常运行,但我希望它能正常工作:-)

I have only tested this on a Mac (which supports the transparent window feature), so I can't really verify it will work as expected on Linux, but I hope it will work fine :-)

import javafx.application.Application; import javafx.application.ConditionalFeature; import javafx.application.Platform; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.ColorPicker; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class SolidPick extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) throws Exception { ColorPicker picker = new ColorPicker(); if (Platform.isSupported(ConditionalFeature.TRANSPARENT_WINDOW)) { Application.setUserAgentStylesheet( this.getClass().getResource( "solid-pick.css" ).toExternalForm() ); } StackPane layout = new StackPane(picker); layout.setPadding(new Insets(10)); stage.setScene(new Scene(layout)); stage.show(); } }

然后将文件solid-pick.css完整复制为整个 modena.css ,并在末尾附加以下几行:

Then the file solid-pick.css an exact copy of the entire modena.css with the following additional lines appended to the end:

.color-palette { -fx-background-radius: 0, 0; -fx-effect: null; }

这些行:

  • 将颜色选择器弹出框设为方形背景,而不是圆形背景.
  • 删除通常围绕弹出窗口的半透明阴影效果.
  • 这些东西的组合为弹出窗口提供了形状和边框,在没有透明窗口的环境中看起来要好得多.

    The combination of these things provide the popup with a shape and border which looks much better in an environment which does not provide transparent windows.

    solid-pick.css文件应与SolidPick应用程序放置在同一目录中,以便将其捆绑到应用程序jar中,并可供应用程序类加载器使用.

    The solid-pick.css file should be placed in the same directory as the SolidPick application, so that it gets bundled into the application jar and will be available to the application classloader.

    示例输出

    这是我的Mac上渲染的一些示例输出,在弹出窗口中带有或不带有阴影阴影边框.

    Here is some sample output of rendering on my Mac with and without the dropshadow border on the popup.

    标准渲染=>

    修改后的渲染,带有正方形边框,没有阴影=>

    Modified rendering, with square borders and no shadow =>

    建议的方法

    遍历整个应用程序(可能还有整个modena.css样式表),并使用与上述颜色选择器相似的方法,解决在透明窗口无法使用的环境中出现的任何渲染问题.然后在您的应用程序中使用生成的样式表,并且(如果获得许可的话)将您的自定义样式表提交给社区,方法是将其提交给第三方项目,例如 ControlsFX .

    Go through your entire application (and possibly the entire modena.css stylesheet) and, using a similar approach to that done above for the color picker, fix up any rendering issues that arise in a transparent window incapable environment. Then use the resultant stylesheet in your application and (if licensing permits), contribute your custom stylesheet to the community by submitting it to a 3rd party project such as ControlsFX.

    更多推荐

    Javafx8 Popup Transparency问题

    本文发布于:2023-10-06 19:42:18,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1467632.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:Popup   Transparency

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!