Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Adding a button and then Killing a thread

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Adding a button and then Killing a thread

    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


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Adding a button and then Killing a thread

    Refer to the API to determine what can and cannot be done with a Thread.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Adding a button and then Killing a thread

    Also posted at: Dealign with thread and button
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Adding a button to every email
    By Newred in forum Web Frameworks
    Replies: 1
    Last Post: January 23rd, 2014, 06:01 AM
  2. GUI Calculator: Adding Answer Button? Please Help
    By Staticity in forum What's Wrong With My Code?
    Replies: 29
    Last Post: July 27th, 2011, 03:18 PM
  3. Killing view of a dead model
    By Alice in forum Java Theory & Questions
    Replies: 9
    Last Post: May 30th, 2011, 05:27 AM
  4. Adding Radio Button Values
    By bazazu in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 13th, 2010, 10:41 AM
  5. Adding fixed size picture and button to panel
    By Javabeginner in forum AWT / Java Swing
    Replies: 10
    Last Post: August 23rd, 2010, 06:07 PM