I have the followign javafx code where It's showing a progressbar updating in 3 sec.
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javafxapplication1; import javafx.application.Application; import javafx.concurrent.Task; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ProgressBar; import javafx.scene.layout.StackPane; import javafx.stage.Stage; /** * * @author me */ public class JavaFXApplication1 extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage stage) { Task<Void> task = new Task<Void>() { @Override public Void call() { for (int i = 1; i < 10; i++) { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(i); updateProgress(i, 10); } return null; } }; ProgressBar updProg = new ProgressBar(); updProg.progressProperty().bind(task.progressProperty()); Thread th = new Thread(task); th.setDaemon(true); th.start(); StackPane layout = new StackPane(); layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;"); layout.getChildren().add(updProg); stage.setScene(new Scene(layout)); stage.show(); } }
1) Basically, I want to add a Button in Icon as shown in Fig 3-2 here.
Using JavaFX UI Controls: Button | JavaFX 2 Tutorials and Documentation
I am wondering, where should I add the following code mentioned in the above link:
Image imageDecline = new Image(getClass().getResourceAsStream("not.png")); Button button5 = new Button(); button5.setGraphic(new ImageView(imageDecline));
2) Then, I would like to kill the thread if a user want to using the button. Is it possible to kill a thread in JavaFX?How should I kill a thread? Please advise
Thanks