ボタンのイベントの中に扇形を設定するコードをかいたのですが、反映されませんでした。
その内容を書いてくれないと、単に「うまくいきませんでした」というだけで何の情報もありません。
コードも変に省略せず実行可能な状態で提示してください(省略すべきは「記録する」ボタン等、質問に関係ない部分です)
ProgressIndicator
はどうでしょうか?
100%理想形ではないでしょうが、妥協できるなら非常に簡単に済みます(minHeight
・minWidth
を入れると大きくできます)
19 進行状況バーと進行状況インジケータ(リリース8)
fxmlは使っているようですが、コントローラはないんでしょうかね?(ちょっとよくわからないんで、回答は通常の構成です)
Java
1package com.example.demo;
2
3import javafx.application.Application;
4import javafx.fxml.FXMLLoader;
5import javafx.scene.Scene;
6import javafx.stage.Stage;
7
8import java.io.IOException;
9
10public class HelloApplication extends Application {
11 public static void main(String[] args) { launch(); }
12
13 @Override public void start(Stage stage) throws IOException {
14 FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
15 Scene scene = new Scene(fxmlLoader.load(), 600, 400);
16 stage.setScene(scene);
17 stage.show();
18 }
19}
Java
1package com.example.demo;
2
3import javafx.fxml.FXML;
4import javafx.scene.control.ProgressIndicator;
5import javafx.scene.layout.Pane;
6import javafx.scene.paint.Color;
7import javafx.scene.shape.*;
8
9public class HelloController {
10 @FXML private Pane root;
11 @FXML private ProgressIndicator progressIndicator;
12 @FXML private Circle circle;
13
14 private int count;
15
16 @FXML protected void onButtonClick() {
17 Arc arc = new Arc(0, 0, circle.getRadius(), circle.getRadius(),
18 360.0 / 9 * count, 360.0 / 9);
19 arc.setLayoutX(circle.getLayoutX());
20 arc.setLayoutY(circle.getLayoutY());
21 arc.setType(ArcType.ROUND);
22 arc.setFill(Color.DODGERBLUE);
23 arc.setStroke(Color.BLACK);
24 root.getChildren().add(arc);
25
26 count++;
27
28 progressIndicator.setProgress(1.0 / 9 * count);
29 }
30}
xml
1<?xml version="1.0" encoding="UTF-8"?>
2
3<?import javafx.scene.control.Button?>
4<?import javafx.scene.control.ProgressIndicator?>
5<?import javafx.scene.layout.Pane?>
6<?import javafx.scene.shape.Circle?>
7
8<Pane fx:id="root" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.demo.HelloController">
9 <ProgressIndicator fx:id="progressIndicator" layoutX="14.0" layoutY="14.0" minHeight="300.0" minWidth="300.0" progress="0.0" />
10 <Button layoutX="279.0" layoutY="355.0" mnemonicParsing="false" onAction="#onButtonClick" text="Button" />
11 <Circle fx:id="circle" fill="#cccccc" layoutX="456.0" layoutY="144.0" radius="130.0" stroke="BLACK" strokeType="INSIDE" />
12</Pane>