| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 
 |  
package testjavafxthread;
 
import java.io.IOException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
 
/**
 *
 */
public class TestJavaFxThread extends Application {
 
 
      BorderPane pane = new BorderPane();
 
    @Override
    public void start(Stage primaryStage) {
 
 
        threadJavafx();
 
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
 
            @Override
            public void handle(ActionEvent event) {
 
 
            }
        });
 
 
        Group group = new Group();
        HBox hbox = new HBox();
        //BorderPane pane = new BorderPane();
 
        hbox.getChildren().add(btn);
        group.getChildren().add(hbox);
        pane.setCenter(group); 
 
 
        Scene scene = new Scene(pane, 300, 250);
 
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
 
    public void a()  {
        Button bouton = new Button();
        Group grp = new Group();
        grp.getChildren().add(bouton);
        pane.setLeft(grp);
 
    }
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
 
 
 
     public void threadJavafx() {
 
          Task longTask = new Task<Void>() {
            @Override
            protected Void call() throws Exception {                             
 
                a();
                return null;
            }
        };           
       new Thread(longTask).start();     
    } | 
Partager