gpt4 book ai didi

具有透明背景的 JavaFX 按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:06:14 24 4
gpt4 key购买 nike

我在 JavaFX 中有一些经典的 Button,带有一个包含一些文本的框。

我需要没有那个框的按钮,只有文本,当我将鼠标悬停在按钮上或用鼠标单击按钮时,它会将其颜色更改为不同。

最佳答案

在 JavaFX 中,样式是通过使用 CSS 完成的。

.button{
-fx-border-color: transparent;
-fx-border-width: 0;
-fx-background-radius: 0;
-fx-background-color: transparent;
-fx-font-family:"Segoe UI", Helvetica, Arial, sans-serif;
-fx-font-size: 1em; /* 12 */
-fx-text-fill: #828282;
}

.button:focused {
-fx-border-color: transparent, black;
-fx-border-width: 1, 1;
-fx-border-style: solid, segments(1, 2);
-fx-border-radius: 0, 0;
-fx-border-insets: 1 1 1 1, 0;
}

.button:pressed {
-fx-background-color: black;
-fx-text-fill: white;
}

将此代码添加到 CSS 文件,将其保存到包含按钮的控件源文件所在的目录。然后在这个类中:

getStylesheets().add(getClass().getResource("nameofyourcssfile.css").toExternalForm());

然后该对象包含的所有按钮都将使用此样式类。

根据您的需要进行修改非常简单。

很好的入门教程: http://docs.oracle.com/javafx/2/css_tutorial/jfxpub-css_tutorial.htm

关于具有透明背景的 JavaFX 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36566197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com