2017-07-13 16 views
1

Javaでタスクマネージャを作成しようとしていますが、進行状況バーを使ってタスクの進行状況を表示しようとしています。プログレスバー全体がタスク全体を示します。私は、灰色で全体的に取り消された進捗状況、計画された進捗状況が緑色、完了した進捗率が緑色でオーバーレイされていることを示す予定です。しかし、私は、Javaが2つの色で塗りつぶしたプログレスバーを達成することを可能にするかどうかは分かりません。誰でも私を啓発できますか?進捗バーに色が異なる2つの進捗状況が表示される

+0

これを見てhttps://stackoverflow.com/questions/10773978/how -to-change-jprogressbar -色 –

答えて

0

複数の色で進行状況バーを表示したい場合は、独自に作成する必要があります。あなたの問題に反映

3

は、私はより多くのcssここ

.progress-bar > .track { 
    -fx-background-color: transparent; 
} 
.progress-bar > .bar { 
    -fx-background-color: transparent;} 
2

で試してみてくださいプログレスバーと

背景を透明にすると、ちょっとあなたが何をしたいかをシミュレートアプリです重なって、ショートカットを考えました。このアプリは2つのProgressBarを使用しています。背景ProgressBarの色は緑色に設定され、その値は100に設定されます。前景のProgressBarは赤色に設定され、通常はProgressBarのように動作し、0.5秒ごとに.01ずつ増分されます。

メイン:

import javafx.animation.KeyFrame; 
import javafx.animation.Timeline; 
import javafx.application.Application; 
import javafx.application.Platform; 
import javafx.beans.property.DoubleProperty; 
import javafx.beans.property.IntegerProperty; 
import javafx.beans.property.SimpleDoubleProperty; 
import javafx.beans.property.SimpleIntegerProperty; 
import javafx.event.Event; 
import javafx.event.EventHandler; 
import javafx.geometry.Pos; 
import javafx.scene.Group; 
import javafx.scene.Scene; 
import javafx.scene.control.Label; 
import javafx.scene.control.ProgressBar; 
import javafx.scene.control.ProgressIndicator; 
import javafx.scene.layout.HBox; 
import javafx.scene.layout.StackPane; 
import javafx.scene.layout.VBox; 
import javafx.stage.Stage; 
import javafx.util.Duration; 

public class ProgressSample extends Application { 

    private final DoubleProperty counter = new SimpleDoubleProperty(0.0); 

    @Override 
    public void start(Stage stage) { 
     Group root = new Group(); 
     Scene scene = new Scene(root, 300, 250); 
     stage.setScene(scene); 
     stage.setTitle("Progress Controls"); 

     ProgressBar pbRed = new ProgressBar(); 
     pbRed.getStylesheets().add(getClass().getResource("ProgressBarColors.css").toExternalForm()); 
     pbRed.getStyleClass().add("red-bar"); 
     pbRed.progressProperty().bind(counter); 

     ProgressBar pbGreen = new ProgressBar();   
     pbGreen.setStyle("-fx-accent: green;"); 
     pbGreen.setProgress(1); 

     final ProgressIndicator piRed = new ProgressIndicator(); 

     ProgressIndicator piGreen = new ProgressIndicator(); 
     piGreen.setProgress(100); 

     StackPane spOne = new StackPane(); 
     spOne.getChildren().addAll(pbGreen, pbRed); 

     Timeline timeline = new Timeline(); 
     timeline.setCycleCount(Timeline.INDEFINITE); 
     timeline.getKeyFrames().add(
       new KeyFrame(Duration.seconds(.5), 
         new EventHandler() { 
        // KeyFrame event handler 
        @Override 
        public void handle(Event event) 
        { 
         counter.set(counter.add(.01).get()); 
         System.out.println(counter.get()); 
        } 
       } 
       )); 
     timeline.playFromStart(); 

     HBox hbox = new HBox(); 
     hbox.getChildren().add(spOne); 

     final VBox vb = new VBox(); 
     vb.getChildren().add(hbox);   
     vb.setSpacing(5); 
     scene.setRoot(vb); 
     stage.show(); 
    } 

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

CSS:

.progress-bar > .track { 
    /*-fx-background-color: transparent ;*/ 
    -fx-control-inner-background: transparent; 
    -fx-text-box-border: transparent; 
} 

.red-bar { -fx-accent: red; } 

enter image description here

関連する問題