- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 JavaFX 的新手,我正在尝试创建一个透明场景并暂存问题是当我添加图像和标签等节点时,场景不再透明这是我的代码
package application;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
public class Main extends Application {
private double xOffset = 0;
private double yOffset = 0;
public void start(Stage primaryStage) throws Exception {
try{
Parent root ;
root = FXMLLoader.load(getClass().getResource("/View/Authentification.fxml"));
primaryStage.initStyle(StageStyle.TRANSPARENT);
Scene scene = new Scene(root);
scene.setFill(null);
root.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
xOffset = event.getSceneX();
yOffset = event.getSceneY();
}
});
root.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
primaryStage.setX(event.getScreenX() - xOffset);
primaryStage.setY(event.getScreenY() - yOffset);
}
});
primaryStage.setScene(scene);
primaryStage.show();}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
这是我的 xml 代码:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane layoutY="94.0" prefHeight="417.0" prefWidth="363.0" style="-fx-background-color: #3D4966;"/>
<AnchorPane layoutX="-1.0" prefHeight="82.0" prefWidth="363.0" style="-fx-background-color: #3D4966;">
<children>
<Label layoutX="280.0" layoutY="70.0" text="Fermer" textFill="#eee5e5">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
<ImageView layoutX="288.0" layoutY="22.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../images/Shutdown.png" />
</image>
</ImageView>
<Label layoutX="146.0" layoutY="61.0" prefHeight="17.0" prefWidth="92.0" text="crée un compte" textFill="#eee5e5">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
<ImageView layoutX="167.0" layoutY="21.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../images/Add_User.png" />
</image>
</ImageView>
<ImageView layoutX="50.0" layoutY="21.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../images/User.png" />
</image>
</ImageView>
<Label layoutX="50.0" layoutY="62.0" text="Ce connecter" textFill="#eee5e5">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
</children>
</AnchorPane>
</AnchorPane>
我尝试了很多其他代码,但似乎没有任何效果这些是一些截图 with nodes
最佳答案
如果您创建一个或多个控件(具体来说,Control
的任何实例或子类),默认样式表将应用于场景。这会将场景根部的背景颜色设置为不透明的“非常浅的灰色”(基本上比 #ececec
亮 26.4%)。
(具体来说,默认样式表包含以下内容:
.root {
/***************************************************************************
* *
* The main color palette from which the rest of the colors are derived. *
* *
**************************************************************************/
/* A light grey that is the base color for objects. Instead of using
* -fx-base directly, the sections in this file will typically use -fx-color.
*/
-fx-base: #ececec;
/* A very light grey used for the background of windows. See also
* -fx-text-background-color, which should be used as the -fx-text-fill
* value for text painted on top of backgrounds colored with -fx-background.
*/
-fx-background: derive(-fx-base,26.4%);
/* ... */
-fx-background-color: -fx-background;
}
可以在 http://hg.openjdk.java.net/openjfx/9/rt/file/c734b008e3e8/modules/javafx.controls/src/main/resources/com/sun/javafx/scene/control/skin/modena/modena.css 找到当前版本的默认样式表(在撰写本文时)的源代码。 ).
所以你也需要让场景的根透明。
您可以在 FXML 中使用内联 CSS 执行此操作:
<AnchorPane style="-fx-background-color: transparent ;" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
或者在 Java 中:
Parent root ;
root = FXMLLoader.load(getClass().getResource("/View/Authentification.fxml"));
root.setStyle("-fx-background-color: transparent ;");
或者您可以在外部样式表中完成:
.root {
-fx-background-color: transparent ;
}
关于JavaFX透明舞台和场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48404440/
如图所示,上面的红色框是一个 GridBox,下面是一个带有 Splitpane (ListView) 和 Gridpane (2 Buttons) 的 VBox。我想要实现的是在单击按钮“隐藏>>"
使用 msfconsole 并搜索 linux x64 有效负载。 我遇到过舞台 Actor 、舞台和单曲?它们都有“reverse_tcp”,可以将连接反转回攻击者。然而我尝试查找舞台 Actor
我正在寻找一种将 3 个 LineCharts 放入单个窗口的方法。我的意思是我想让它们并排放置,或者一个在另一个下面。 我一直在寻找实现它的方法,但找不到任何东西。我试图搜索如何将多个场景放入一个阶
我有一个有效的 Web 功能,它使用 html5 视频和 Canvas 来访问设备相机的媒体流,然后拍照并在 Canvas 中渲染图像。效果很好,但我想使用 konvajs stage 而不是 can
我在解决这个问题时遇到了困难,并且我找不到我遇到的这个问题的正确答案。我希望将一个场景/阶段用作打开另一个场景/阶段的按钮,并且两者都通过相同的方法调用。完整的方法如下: public void c
我在 JavaFX 上有一个简单的应用程序,它实际上由几个 Pane 和按钮组成。我不知道如何在舞台调整大小时移动按钮。所以,我希望左下角的按钮即使在调整窗口大小时也始终可见。 这里是节点概览: 这里
来自 Swing 并且是 JavaFX 的新手,我尝试对 Java FX Stages 和 Scenes 进行子类化。但是我很快就遇到了问题,比如初始化过程中找不到我的子类场景的 init 方法。 所
How to animate or move window using clutter_actor_animate? Here's my code and it didn't work. clutte
有没有办法从关联的类 Controller 中获取 FXML 加载文件的 Stage/Window 对象? 特别是,我有一个模态窗口 Controller ,我需要舞台来关闭它。 最佳答案 我找不到解
我将工作代码分为 2 个文件以避免困惑。以前确实有效,但是将所有场景都放在一个类中是非常不愉快的。 以前,当您单击 Sprite 时,它会将您从菜单带到游戏。然后我将游戏组和游戏场景的代码提取到游戏类
我希望能够将 HTML 文本转换为位图,以便在 AlivePDF 中使用。我的测试适用于 TextArea,或者组件是否在舞台上或可见。但我希望能够处理不一定位于屏幕上的文本块。有谁知道如何做到这一点
我有一个 swing 应用程序,我需要在其中运行并打开 JavaFX 场景/阶段。我必须在没有扩展应用程序的情况下运行它。我已经尝试了 Stackoverflow 上发布的大多数解决方案,但没有一个适
我正在寻找一种方法来缩小 Flash 文件的高度。我可以更改宽度,但高度似乎与其所在窗口的大小有关? http://www.bevelite.com.au/test 我正在使用 page-flip.c
我需要在选择组合框元素时重新绘制窗口。如何在 JAVA FX 2.2 中重绘窗口(舞台)? 下面是我的代码 functionComboBox.valueProperty().addListener(n
我是一名优秀的程序员,十分优秀!