Yon*_* Wu 7 icons javafx slider
我想将图标更改为我的图像,我查看了CSS参考指南,但我似乎无法找到任何相关内容.它甚至可能吗?无论是使用CSS还是从主JavaFX脚本声明性地无关紧要.
请查看示例代码以及如何在此AudioPlayer中呈现自定义滑块的图像.
如果您只想要反馈而不是交互式控件,JFXtras库还有许多仪表.
下面是一些使用由invariant的答案指出的选择器的示例css.请注意,我需要在图像尺寸的一半处添加-fx-padding规范,以便显示整个图像.
/** slider.css
place in same directory as SliderCss.java
ensure build system copies the css file to the build output path */
.slider .thumb {
-fx-background-image :url("http://icons.iconarchive.com/icons/double-j-design/diagram-free/128/piggy-bank-icon.png");
-fx-padding: 64;
}
/* Icon license: creative commons with attribution: http://www.doublejdesign.co.uk/products-page/icons/diagram */
Run Code Online (Sandbox Code Playgroud)
示例应用:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
public class SliderCss extends Application {
public static void main(String[] args) { launch(args); }
@Override public void start(Stage stage) throws Exception {
VBox layout = new VBox();
layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10px;");
layout.getChildren().setAll(new Slider());
layout.getStylesheets().add(getClass().getResource("slider.css").toExternalForm());
stage.setScene(new Scene(layout));
stage.show();
}
}
Run Code Online (Sandbox Code Playgroud)
示例程序输出:


你可以用css改变滑块的拇指
.slider .thumb{
-fx-background-image :url("your image");
...// more customization
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9542 次 |
| 最近记录: |