如何获取JavaFX中的进度条? [英] How to get narrow progres bar in JavaFX?

查看:559
本文介绍了如何获取JavaFX中的进度条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如标题所示,我需要做一个细长的进度条。我使用这个:

  progressBar.setMaxHeight(0.1); 
progressBar.setPrefHeight(0.1);

但不起作用。有人有想法吗?

解决方案

你必须搞定样式,我真的推荐看看一个 caspian.css 包括在Javafx - 这是默认样式表。当尝试覆盖默认皮肤的外观和感觉时,它有很多帮助。下面是一个我放在一起的例子,显示了如何做:

  import javafx.application.Application; 
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;


public class ProgressBarTest extends应用程序{

public static void main(String [] args){launch(args); }

@Override
public void start(final Stage stage)throws Exception {
//所有控件都添加到这里
VBox box = new VBox();
box.getStylesheets()。add(test.css);
ProgressBar pb = new ProgressBar(50);

box.getChildren()。add(pb);

//设置场景
场景scene = new Scene(box);
stage.setScene(scene);

stage.show();
}
}

这里是我加载的test.css: / p>

  .progress-bar .bar {-fx-padding:1px; -fx-background-insets:0;} 

这里是测试应用程序的输出: / p>


As the title says, I need to make a thin progress bar. I used this:

progressBar.setMaxHeight(0.1);
progressBar.setPrefHeight(0.1);

but that doesn't work. Does anyone have an idea?

解决方案

You'll have to mess around with the styling to get it any smaller. I really recommend taking a look a the caspian.css that's included with Javafx - that's the default style sheet. It helps a lot when trying to override the look and feel of the default skins. Here's an example I put together that shows how it can be done:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;


public class ProgressBarTest extends Application {

    public static void main(String[] args) { launch(args); }

    @Override
    public void start(final Stage stage) throws Exception {
        //All the controls are added here
        VBox box = new VBox();
        box.getStylesheets().add("test.css");
        ProgressBar pb = new ProgressBar(50);

        box.getChildren().add(pb);

        //Setting up your scene
        Scene scene = new Scene(box);
        stage.setScene(scene);

        stage.show();
    }
}

And here's the test.css I loaded up:

.progress-bar .bar {-fx-padding:1px; -fx-background-insets:0;}

And here is the output of the test app:

这篇关于如何获取JavaFX中的进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆