Draggable Stage in JavaFX 1.2 - flickering

Hello,
i am rewriting an application to JavaFX 1.2
now i have the problem that my window/stage is flickering when i want to move it over my desktop. Here is an example. Does anybody knows a solution?
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.StageStyle;
var stage:Stage;
stage = Stage {
    title: "Application title"
    width: 250
    height: 80
    style: StageStyle.TRANSPARENT
    scene: Scene {
        fill: Color.BLUE
        content: [
           Rectangle {
               blocksMouse: true
                width: bind stage.scene.width
                height: bind stage.scene.height
                fill: Color.TRANSPARENT
                onMouseDragged: function( e: MouseEvent ):Void {
                    stage.x += e.dragX;
                    stage.y += e.dragY;
            Text {
                font : Font {
                    size : 16
                x: 10
                y: 30
                content: "Application content"
}Riepi

Please use below code..
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.StageStyle;
var stage:Stage;
var stageDragInitialX : Number;
var stageDragInitialY : Number;
stage = Stage {
    title: "Application title"
    width: 250
    height: 80
    style: StageStyle.TRANSPARENT
    scene: Scene {
        fill: Color.BLUE
        content: [
           Rectangle {
               blocksMouse: true
                width: bind stage.scene.width
                height: bind stage.scene.height
                fill: Color.TRANSPARENT
                onMousePressed: function( e: MouseEvent ):Void {
                    stageDragInitialX = e.screenX - stage.x;
                    stageDragInitialY = e.screenY - stage.y;
                onMouseDragged: function( e: MouseEvent ):Void {
                    stage.x = e.screenX - stageDragInitialX;
                    stage.y = e.screenY - stageDragInitialY;
            Text {
                font : Font {
                    size : 16
                x: 10
                y: 30
                content: "Application content"
}

Similar Messages

  • Problem with Draggable Applet in JavaFX Samples

    I am looking at JavaFX Samples which run as Draggable Applets - for example, DisplayShelf and EffectsPlayground. I ran into a problem while running these samples from Netbeans 6.5 IDE. It seems that there is a problem with the logic in this line of code in Main.fx:
    var inBrowser = "true".equals(FX.getArgument("isApplet") as String);I found that this expression is evaluating to false because the "isApplet" argument is null, such that the drag and drop installation is not available. When toggling the Properties > Application > Draggable Applet checkbox, I found that the html page generated to launch the applet (e.g. DisplayShelf/dist/DisplayShelf.html) would simply add/remove draggable argument:
    <script>
        javafx(
                  archive: "DisplayShelf.jar",
                  *draggable: true,*
                  width: 600,
                  height: 300,
                  code: "displayshelf.Main",
                  name: "DisplayShelf"
    </script>Given this, shouldn't the Samples actually have logic as follows:
    var inBrowser = "true".equals(FX.getArgument("draggable") as String);

    Thanks, this works and is probably the better solution, as the draggable argument can be set even when not running from browser. Thanks!
    But my concern is that the code in the draggable app Samples which come with Netbeans IDE do not work correctly, because FX.getArgument("isApplet") returns null. Would this be something to file a bug for? Seems like other newbies like me would get confused when the samples don't work....

  • Resizing undecorated Stage on Mac OS X flickers

    Hello.
    I am developing a small application on Windows. Now i tried how it works on Mac OS X. I run into trouble when i was resizing my custom Window. It is flickering while resizing. On Windows following code works finde. Perhaps someone knows a workaround?
    var stage:Stage;
    stage = Stage {
                title : "MacTest"
                style: StageStyle.TRANSPARENT
                scene: Scene {
                        width: 900
                        height: 700
                        fill: null
                        content:[
                            Rectangle{
                                layoutX: bind stage.scene.width - 20
                                layoutY: bind stage.scene.height - 20
                                smooth: false
                                var helpX;
                                var helpY;
                                width: 20
                                height: 20
                                fill: Color.ANTIQUEWHITE
                                blocksMouse: true
                                cursor:Cursor.SE_RESIZE
                                onMousePressed: function( e: MouseEvent ):Void {
                                    helpX = stage.scene.width;
                                    helpY = stage.scene.height;
                                onMouseDragged: function(e:MouseEvent):Void {
                                    var endX = (e.dragX as Integer);
                                    var endY = (e.dragY as Integer);
                                    if((helpX + endX) > 100 and (helpX + endX) < 1400 ){
                                        stage.width = helpX + endX as Integer;
                                    if((helpY + endY) > 100 and (helpY + endY) < 1200 ){
                                        stage.height = helpY + endY as Integer;
        }Riepi

    Thanks mate but Software update is indicating that I am all up to date.
    I have booted off an older clone and mail was fine. I may have to go for a fresh install of the system but it annoys me to have to do that. It's gotta be something simple!

  • JavaFX 2.0 Stage onClose event

    There is an event / handler to make some verification to confirm or not a stage close ?
    There is onHiding() but this don´t cancel or block stage close.
    Any idea ?
    Regards,
    Jean Paul Lopes

    Couldn't find a way to keep the primary Stage open, but this is the closest I could get. See the documentation for Platform@runLater, particularly the guarantee that
    The Runnables are executed in the order they are posted. A runnable passed into the runLater method will be executed before any Runnable passed into a subsequent call to runLater.
    import javafx.application.Application;
    import javafx.application.Platform;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.geometry.Pos;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.layout.FlowPane;
    import javafx.scene.layout.VBox;
    import javafx.stage.Modality;
    import javafx.stage.Stage;
    import javafx.stage.WindowEvent;
    public class ConfirmClose extends Application {
      public static void main(String[] args) {
        Application.launch(args);
      @Override
      public void start(final Stage primaryStage) throws Exception {
        primaryStage.setOnHiding(new EventHandler<WindowEvent>() {
          @Override
          public void handle(WindowEvent event) {
            Platform.runLater(new Runnable() {
              @Override
              public void run() {
                primaryStage.setVisible(true);
            final Stage dialog = new Stage();
            dialog.initModality(Modality.APPLICATION_MODAL);
            Label label = new Label("Really exit?");
            Button okButton = new Button("OK");
            okButton.setOnAction(new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent event) {
                dialog.hide();
                Platform.runLater(new Runnable() {
                  @Override
                  public void run() {
                    primaryStage.setOnHiding(null);
                    primaryStage.hide();
            Button cancelButton = new Button("Cancel");
            cancelButton.setOnAction(new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent event) {
                dialog.hide();
            FlowPane pane = new FlowPane(10, 10);
            pane.setAlignment(Pos.CENTER);
            pane.getChildren().addAll(okButton, cancelButton);
            VBox vBox = new VBox(10);
            vBox.setAlignment(Pos.CENTER);
            vBox.getChildren().addAll(label, pane);
            Scene scene1 = new Scene(vBox);
            dialog.setScene(scene1);
            Platform.runLater(new Runnable() {
              @Override
              public void run() {
                dialog.initOwner(primaryStage);
                dialog.setVisible(true);
        primaryStage.setVisible(true);
    }Debugging shows that the Stage is actually hidden when the setOnHiding's EventHandler's handle(...) returns. It also shows that, unlike in Swing, showing a modal dialog doesn't suspend the application thread.
    db

  • Javafx deployment in html page(please help me urgent)

    i used the following method to deploy javafx in an html page.
    javafx file is:
    package hello;
    import javafx.scene.*;
    import javafx.stage.Stage;
    import javafx.scene.text.Text;
    import javafx.scene.text.Font;
    import javafx.scene.paint.Color;
    import javafx.scene.effect.DropShadow;
    Stage {
        title: "My Applet"
        width: 250
        height: 80
        scene: Scene {
            content: Text {
                x: 10  y: 30
                font: Font {
                     size: 24 }
                fill: Color.BLUE
                effect: DropShadow{ offsetX: 3 offsetY: 3}
                content: "VAARTA"
    I save the file as HelloApplet in a 'hello' named folder in my D:
    after that i downloaded from internet html code as
    <html>
        <head>
            <title>Wiki</title>
        </head>
        <body>
            <h1>Wiki</h1>
            <script src="dtfx.js"></script>
            <script>
                javafx(
                    archive: "HelloApplet.jar",
                    draggable: true,
                    width: 150,
                    height: 100,
                    code: "hello.HelloApplet",
                    name: "Wiki"
            </script>
        </body>
    </html>now i typed in DOS prompt as javafxc.exe HelloApplet.fx & i got the class files .
    _The main problem which is coming is how to create HelloApplet.jar file which is used in the html page without which the html page is not displaying the javafx script. Please help me urgently i am in the middle of my project & stuck up due to JAVAFX                   i am using WIndowsXP & javafx-sdk1.0 when i am typing jar command inside hello package it is displaying invalid command.in DOS prompt. If there is any other method to deploy javafx in html page then specify it also.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Crossposted: [http://forums.sun.com/thread.jspa?threadID=5323288].
    Please don't crosspost without notifying others. It is rude in terms of netiquette. Stick to one topic.

  • How to let Stage size adjust to size of applet ?

    Sirs and madams,
    I need to deploy an app online. There is going to be lots of stuff on the Stage.
    To keep possible damage to user's eye minimal i would like to adjust the size of the Stage and
    it's components to the size of the applet.
    Is such a thing possible? If yes - how?
    Thanks in advance!

    The size of the applet is defined in the HTML file generated by javafxpackager (or NetBeans using the latter):
    <script>
        javafx(
                  archive: "JavaFXProgram.jar",
                  draggable: true,
                  width: 1024,
                  height: 768,
                  code: "JavaFXProgram",
                  name: "JavaFXProgram"
    </script>In general, you define these values to the size of the stage, not the way around...
    Although, I suppose you can generate these sizes if you generate dynamically the page (eg. with a JSP or something similar).
    You can get these values with FX.getArgument(), and size the stage with them:
    def WIDTH: Integer = Integer.parseInt(FX.getArgument('width') as String);
    def HEIGHT: Integer = Integer.parseInt(FX.getArgument('height') as String);
    Stage
      title: "JavaFX Packaging and Deployment Test"
      width: WIDTH
      height: HEIGHT
      scene: scene
    }

  • How can I select multiple cells in tableview with javafx only by mouse?

    I have an application with a tableview in javafx and i want to select multiple cells only by mouse (something like the selection which exists in excel).I tried with setOnMouseDragged but i cant'n do something because the selection returns only the cell from where the selection started.Can someone help me?

    For mouse drag events to propagate to nodes other than the node in which the drag initiated, you need to activate a "full press-drag-release gesture" by calling startFullDrag(...) on the initial node. (See the Javadocs for MouseEvent and MouseDragEvent for details.) Then you can register for MouseDragEvents on the table cells in order to receive and process those events.
    Here's a simple example: the UI is not supposed to be ideal but it will give you the idea.
    import java.util.Arrays;
    import javafx.application.Application;
    import javafx.beans.property.SimpleStringProperty;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.event.EventHandler;
    import javafx.geometry.Insets;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.SelectionMode;
    import javafx.scene.control.TableCell;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.input.MouseDragEvent;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.VBox;
    import javafx.scene.text.Font;
    import javafx.stage.Stage;
    import javafx.util.Callback;
    public class DragSelectionTable extends Application {
        private TableView<Person> table = new TableView<Person>();
        private final ObservableList<Person> data =
            FXCollections.observableArrayList(
                new Person("Jacob", "Smith", "[email protected]"),
                new Person("Isabella", "Johnson", "[email protected]"),
                new Person("Ethan", "Williams", "[email protected]"),
                new Person("Emma", "Jones", "[email protected]"),
                new Person("Michael", "Brown", "[email protected]")
        public static void main(String[] args) {
            launch(args);
        @Override
        public void start(Stage stage) {
            Scene scene = new Scene(new Group());
            stage.setTitle("Table View Sample");
            stage.setWidth(450);
            stage.setHeight(500);
            final Label label = new Label("Address Book");
            label.setFont(new Font("Arial", 20));
            table.setEditable(true);
            TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name");
            firstNameCol.setMinWidth(100);
            firstNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("firstName"));
            TableColumn<Person, String> lastNameCol = new TableColumn<>("Last Name");
            lastNameCol.setMinWidth(100);
            lastNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("lastName"));
            TableColumn<Person, String> emailCol = new TableColumn<>("Email");
            emailCol.setMinWidth(200);
            emailCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("email"));
            final Callback<TableColumn<Person, String>, TableCell<Person, String>> cellFactory = new DragSelectionCellFactory();
            firstNameCol.setCellFactory(cellFactory);
            lastNameCol.setCellFactory(cellFactory);
            emailCol.setCellFactory(cellFactory);
            table.setItems(data);
            table.getColumns().addAll(Arrays.asList(firstNameCol, lastNameCol, emailCol));
            table.getSelectionModel().setCellSelectionEnabled(true);
            table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
            final VBox vbox = new VBox();
            vbox.setSpacing(5);
            vbox.setPadding(new Insets(10, 0, 0, 10));
            vbox.getChildren().addAll(label, table);
            ((Group) scene.getRoot()).getChildren().addAll(vbox);
            stage.setScene(scene);
            stage.show();
        public static class DragSelectionCell extends TableCell<Person, String> {
            public DragSelectionCell() {
                setOnDragDetected(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        startFullDrag();
                        getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn());
                setOnMouseDragEntered(new EventHandler<MouseDragEvent>() {
                    @Override
                    public void handle(MouseDragEvent event) {
                        getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn());
            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (empty) {
                    setText(null);
                } else {
                    setText(item);
        public static class DragSelectionCellFactory implements Callback<TableColumn<Person, String>, TableCell<Person, String>> {
            @Override
            public TableCell<Person, String> call(final TableColumn<Person, String> col) {         
                return new DragSelectionCell();
        public static class Person {
            private final SimpleStringProperty firstName;
            private final SimpleStringProperty lastName;
            private final SimpleStringProperty email;
            private Person(String fName, String lName, String email) {
                this.firstName = new SimpleStringProperty(fName);
                this.lastName = new SimpleStringProperty(lName);
                this.email = new SimpleStringProperty(email);
            public String getFirstName() {
                return firstName.get();
            public void setFirstName(String fName) {
                firstName.set(fName);
            public String getLastName() {
                return lastName.get();
            public void setLastName(String fName) {
                lastName.set(fName);
            public String getEmail() {
                return email.get();
            public void setEmail(String fName) {
                email.set(fName);

  • How can I implement a comfirmation window when closing javafx application?

    hi,guys
    I'd like to add a confirmation window when user is closing my javafx application,if user click yes, I will close the application,if no ,I wouldn't close it ,how can I implement this function?
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
                   @Override
                   public void handle(WindowEvent arg0) {
                        try
                             //todo
                        catch(Exception ex)
                             System.out.print(ex.getMessage()+"\r\n");
            });

    Hi. Here is an example:
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.geometry.Pos;
    import javafx.stage.*;
    import javafx.scene.*;
    import javafx.scene.paint.Color;
    import javafx.scene.layout.*;
    import javafx.scene.control.*;
    public class ModalDialog {
        public ModalDialog(final Stage stg) {
         final Stage stage = new Stage();          
            //Initialize the Stage with type of modal
            stage.initModality(Modality.APPLICATION_MODAL);
            //Set the owner of the Stage
            stage.initOwner(stg);
            Group group =  new Group();
            HBox hb = new HBox();
             hb.setSpacing(20);
            hb.setAlignment(Pos.CENTER);
            Label label = new Label("You are about to close \n your application: ");
            Button no  = new Button("No");
            no.setOnAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent event) {
                       stage.hide();
            Button yes  = new Button("Yes");
            yes.setOnAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent event) {
                       stg.close();
             hb.getChildren().addAll(yes, no);
             VBox vb =  new VBox();
             vb.setSpacing(20);
             vb.setAlignment(Pos.CENTER);
             vb.getChildren().addAll(label,hb);
            stage.setTitle("Closing ...");
            stage.setScene(new Scene( vb, 260, 110, Color.LIGHTCYAN));       
            stage.show();
    }Test:
       import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    import javafx.stage.*;
    * @author Shakir
    public class ModalTest extends Application {
         * @param args the command line arguments
        public static void main(String[] args) {
            Application.launch(ModalTest.class, args);
        @Override
        public void start(final Stage primaryStage) {
            primaryStage.setTitle("Hello World");
            Group root = new Group();
            Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN);
           primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
                   @Override
                   public void handle(WindowEvent arg0) {
                                    arg0.consume();
                        try
                         ModalDialog md = new ModalDialog(primaryStage);
                        catch(Exception ex)
                             System.out.print(ex.getMessage()+"\r\n");
            primaryStage.setScene(scene);
            primaryStage.show();
    }

  • Delay program until end TranslateTransition JavaFX

    Hey everyone,
    My name is Thomas and I am currently working on a final High School programming project. For this project we are programming a game with JavaFX, in which we feature several mini-games to improve children's mathematical skills. One of about 10 mini-games is a puzzle where you have to reach the exit of the level by sliding over ice.
    Let me explain the mechanics of this mini-game. When you press an arrow the character has to keep sliding in that direction until it bumps into an object (I have four rocks & borders of the map). What I decided to do is make a function for each direction in which I define a translation of a certain distance, and then keep repeating this translation until there is an object right next to the character, at which time it will stop moving. In many programming languages this would be an easy task, but there is a problem in JavaFX: when I execute the translation the code will continue executing, allowing the user to press a button while still moving which should not be allowed: the code has to wait until the movement is complete. Most languages have a delay(x ms) function for this, but JavaFX does not have one.
    I was wondering whether anyone knows a solution for this problem. I need to make a delay either in the TranslateTransition, or in a function since I made a while loop that keeps executing the translation but without a delay it executes the transition a million times.
    Any help will be greatly appreciated!
    Thomas Brouwer
    The code (with the loop I talked about as comments since it freezes the program):
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package javafx.toneel.pac;
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.input.KeyCode;
    import javafx.scene.input.KeyEvent;
    import javafx.scene.paint.Color;
    import javafx.animation.transition.TranslateTransition;
    import javafx.animation.*;
    var character: Rectangle;
    def scenewidth = 600;
    def sceneheight = 600;
    var topborder: Rectangle;
    var leftborder: Rectangle;
    var rightborder: Rectangle;
    var bottomborder: Rectangle;
    var Moving = false;
    var object1: Rectangle;
    var object2: Rectangle;
    var object3: Rectangle;
    var object4: Rectangle;
    var minX = scenewidth/12;
    var minY = sceneheight/12;
    var maxX = 11*scenewidth/12;
    var maxY = 11*sceneheight/12;
    * @author Thomas
    Stage {
    title: "Application title"
    scene: Scene {
    width: scenewidth
    height: sceneheight
    content: [
    //code to make the borders of the map. The map consists of blocks 10x10 and
    //another block as borders on each side, so 12 horizontally and 12 vertically
    topborder = Rectangle {
    width: scenewidth
    height: sceneheight/12
    x: 0
    y: 0
    fill: Color.BLUE
    leftborder = Rectangle {
    width: scenewidth/12
    height: sceneheight
    x: 0
    y: 0
    fill: Color.BLUE
    rightborder = Rectangle {
    width: scenewidth/12
    height: sceneheight
    x: 11*scenewidth/12
    y: 0
    fill: Color.BLUE
    bottomborder = Rectangle {
    width: scenewidth
    height: sceneheight/12
    x: 0
    y: 11*sceneheight/12
    fill: Color.BLUE
    //code to define the character
    character = Rectangle {
    width: scenewidth/12
    height: scenewidth/12
    x: 6*scenewidth/12
    y: 6*sceneheight/12
    fill: Color.BLUE
    //make the keyevent input accessible
    focusTraversable:true
    onKeyPressed: function( e: KeyEvent ) {
    //prevent key input while the object is already moving, but this
    //does not work either.
    if (Moving == false){
    if (e.code == KeyCode.VK_LEFT) {
    Moving = true;
    Movingcheckleft();
    if (e.code == KeyCode.VK_RIGHT) {
    Moving = true;
    Movingcheckright();
    if (e.code == KeyCode.VK_UP) {
    Moving = true;
    Movingcheckup();
    if (e.code == KeyCode.VK_DOWN) {
    Moving = true;
    Movingcheckdown();
    //code to define the objects
    object1 = Rectangle {
    width: scenewidth/12
    height: sceneheight/12
    x: 10*scenewidth/12 //one square from the rightborder
    y: sceneheight/12
    fill: Color.YELLOW
    object2 = Rectangle {
    width: scenewidth/12
    height: sceneheight/12
    x: 9*scenewidth/12 //two squares from the rightborder
    y: 8*sceneheight/12 //three squares from the bottomborder
    fill: Color.YELLOW
    object3 = Rectangle {
    width: scenewidth/12
    height: sceneheight/12
    x: 6*scenewidth/12 //five squares from the leftborder
    y: 7*sceneheight/12 //four squares from the bottomborder
    fill: Color.YELLOW
    object4 = Rectangle {
    width: scenewidth/12
    height: sceneheight/12
    x: 7*scenewidth/12 //four squares from the rightborder
    y: 2*sceneheight/12 //two squares from the topborder
    fill: Color.YELLOW
    function Movingcheckleft() {
    //move one square to the left
    var Transitionleft = TranslateTransition {
    node: character
    duration: 200ms
    byX: (-scenewidth/12)
    interpolator: Interpolator.LINEAR
    //check whether there is an object right of the character. As long as there isn't, the
    //character will move 1 square to the right. However, while expressions do not seem
    //to work in combination with Transition.play.
    //while (((character.x - scenewidth/12) != (object1.x)) and ((character.x - scenewidth/12) != (object2.x)) and ((character.x - scenewidth/12) != (object3.x)) and ((character.x - scenewidth/12) != (object4.x)) and (character.x != minX)){
    Transitionleft.play();
    Moving = false;
    x = 0;
    function Movingcheckright() {
    var Transitionright = TranslateTransition {
    node: character
    duration: 200ms
    byX: (scenewidth/12)
    interpolator: Interpolator.LINEAR
    //while (((character.x + scenewidth/12) != (object1.x)) and ((character.x + scenewidth/12) != (object2.x)) and ((character.x + scenewidth/12) != (object3.x)) and ((character.x + scenewidth/12) != (object4.x)) and (character.x != maxX)){
    Transitionright.play();
    Moving = false;
    function Movingcheckup() {
    var Transitionup = TranslateTransition {
    node: character
    duration: 200ms
    byY: (-sceneheight/12)
    interpolator: Interpolator.LINEAR
    //while (((character.y - sceneheight/12) != (object1.y)) and ((character.y - sceneheight/12) != (object2.y)) and ((character.y - sceneheight/12) != (object3.y)) and ((character.y - sceneheight/12) != (object4.y)) and (character.y != minY)){
    Transitionup.play();
    Moving = false;
    function Movingcheckdown() {
    var Transitiondown = TranslateTransition {
    node: character
    duration: 200ms
    byY: (sceneheight/12)
    interpolator: Interpolator.LINEAR
    //while (((character.y + sceneheight/12) != (object1.y)) and ((character.y + sceneheight/12) != (object2.y)) and ((character.y + sceneheight/12) != (object3.y)) and ((character.y + sceneheight/12) != (object4.y)) and (character.y != maxY)){{
    Transitiondown.play();
    Moving = false;
    }

    please manage your coding pattern before you post any topic!!
    Make forum helper easy to recognize your problem..

  • Remaining questions while evaluating JavaFX for a new project

    Dear forum members:
    currently I am evaluating the possibilities of next-generation GUI technologies, such as JavaFX, Silverlight and Flash/Flex, for a new project. To get a basic understanding of JavaFX's concepts, I worked through the available online text and video tutorials, and all the treated topics seem quite obvious/comprehensible to me +as long as one is only confronted to relatively static GUI component hierarchies+. But, as a newbie, some questions concerning more dynamically defined GUIs (i.e. dynamic JFX scripting*) still remain.
    Application scenario (exemplary):
    Say I want to create a "Online Shopping Application" that supports "+ShopOwners+" in *dynamically* defining the "+Shop Model+" structure, e.g. accepted visitor (client) categories, product categories their products, pricing information, payment methods, etc.
    Then, based on the dynamically defined model, the shop owner should be able to design and layout the necessary forms, such as order forms, survey/feedback forms, etc. This should be done in "design mode", and there should also exist a possibility for him/her to preview the specification results in a "preview mode".
    Finally, the shop owner must be able to save the model and forms on the server side in a way that can requested and run be the shopping app end users (the shop clients) via (another (?)) JavaFX frontend.
    _The still remaining questions for this scenario are:_
    +1. Is JavaFX appropriate for creating such kind of applications, especially when it comes to dynamic JFX scripting (and compilation) on the client side??? (By now I'm not quite sure if this is really necessary for my plans!)+
    +2. Concerning the ShopOwner's GUI with its design and preview mode (and knowing that the latter mode will be the GUI version presented to the shop clients in another JFX module):+
    +Is it possible to *dynamically *build up a +Scene Graph+ in a way that lets me handle and *compile* the corresponding +JFX Script+ on the client side for previewing it? Or is a client-server roundtrip absolutely necessary?
    How could one persist this JFX Script on the server side? I.e., which intermediary format would be the most appropriate? => XML, JSON, JFX Script?
    3. Concerning the "Shop Model", would I optimally create JFX classes or even Java Beans to bind to?
    4. And finally: What would be your recommended way (software architecture) to fulfill this task in JavaFX?
    Do there already exist some JFX components (dynamic forms/survey authoring modules, etc.) that persue a similar task and that I didn't find yet?
    As the clarification of the above-mentioned issues are very important for me, I hope that you more experienced users can help me, pointing me to a practicable approach.
    Thank you very much for any help and constructive tips in advance.
    Best regards
    Martin Meyers

    Q1: Do I optimally need 2 different custom components for each treated concept, or do I have just 1 component with 2 internal modes (design & preview/usage)??
    E.g., (a) FormSpec widget composed of LabelSpec, TextBoxSpec, ChooseBoxSpec,... widgets each having their preview pendants
    Form, Label, TextBox, ChooseBox, etc.
    versus
    +(b) only Form widget composed of Label, TextBox, ChooseBox widgets, but all having a "design/preview execution mode".+
    Closer to (b), I think, though each widget doesn't need to be modified to have design and preview modes. Instead, each widget can be wrapped within a Group to provide the design/preview functions without modifying the widget itself.
    The technique is as follows. Given a sequence of widgets (Nodes, really), for each widget, wrap it in a Group that contains that widget but with an overlay Rectangle in front of it. The Rectangle can be semi-transparent, or fully transparent if you prefer. (In the example below I've made it a semitransparent color to make its location obvious as well as to provide a highlight that signals design mode.) The overlay Rectangle is set up so that its dimensions will exactly track the dimensions (bounds) of the widget behind it. I've set blocksMouse to true so that when it's present, the overlay traps events and prevents interaction with the widget. There is a boolean variable previewMode, controlled by a CheckBox, that controls the visibility of these overlay rectangles. I've also added a bit of code to track mouse events on the overlay rectangles so that you can move the widgets around when you're in design mode.
    Note that the visible variable differs from transparent, i.e. opacity == 0.0. If a node is visible but is transparent, it is still eligible to receive events; whereas if visible is false, it does not receive events.
    Here's some code that illustrates this technique. I'll answer your other questions in a subsequent post.
    import javafx.stage.Stage;
    import javafx.scene.*;
    import javafx.scene.control.*;
    import javafx.scene.input.*;
    import javafx.scene.layout.*;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.paint.Color;
    var previewMode = true;
    var lastX:Number;
    var lastY:Number;
    function wrap(n:Node):Node {
        Group {
            content: [
                n,
                Rectangle {
                    opacity: 0.2
                    fill: Color.web("#ffff00")
                    x: bind n.boundsInParent.minX
                    y: bind n.boundsInParent.minY
                    width: bind n.boundsInParent.width
                    height: bind n.boundsInParent.height
                    visible: bind previewMode
                    blocksMouse: true
                    onMousePressed: function(me:MouseEvent) {
                        lastX = me.x;
                        lastY = me.y;
                    onMouseDragged: function(me:MouseEvent) {
                        n.layoutX += me.x - lastX;
                        n.layoutY += me.y - lastY;
                        lastX = me.x;
                        lastY = me.y;
    var controlList:Node[] = [
        Button {
            layoutX: 140
            layoutY: 20
            text: "Button1"
            action: function() { println("Button1 clicked!"); }
        Slider {
            layoutX: 30
            layoutY: 60
            min: 0
            max: 100
            override var value on replace {
                println("Slider value is now {value}");
        Label {
            layoutX: 50
            layoutY: 100
            text: "Non-interactive label"
        CheckBox {
            layoutX: 40
            layoutY: 140
            text: "CheckBox"
            override var selected on replace {
                println("CheckBox is now {if (selected) "checked" else "unchecked"}");
    Stage {
        title: "Design vs Preview Mode"
        width: 400
        height: 250
        scene: Scene {
            content: [
                CheckBox {
                    layoutX: 10
                    layoutY: 10
                    text: "Preview Mode"
                    selected: bind previewMode with inverse
                Panel {
                    content: for (n in controlList) {
                        wrap(n)
    }

  • Java run time error while executing JavaFX code

    Hi
    I copied the code from [http://java.sun.com/javafx/1/tutorials/ui/overview/UIControls.fx|http://java.sun.com/javafx/1/tutorials/ui/overview/UIControls.fx] while
    reading in [http://java.sun.com/javafx/1/tutorials/ui/overview/#controls|http://java.sun.com/javafx/1/tutorials/ui/overview/#controls] tutorial and paste it to my
    netbeans editor but i got following error.
    init:
    deps-jar:
    compile:
    jar:
    standard-run:
    # An unexpected error has been detected by Java Runtime Environment:
    #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d94513f, pid=5152, tid=5996
    # Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode, sharing)
    # Problematic frame:
    # V  [jvm.dll+0xd513f]
    # An error report file with more information is saved as hs_err_pid5152.log
    # If you would like to submit a bug report, please visit:
    #   http://java.sun.com/webapps/bugreport/crash.jsp
    BUILD FAILED (total time: 18 seconds)can anyone tell whether its netbeans fault or javaFX. I am using netbeans 6.5.1 on windows vista. I have added following plugin in netbeans for javaFX
    *JavaFX Kit
    *JavaFX SDK for Windows
    is anyone also getting this error for this code and have solution for this.

    You are correct the crash is causing due to ToggleButton and ProgessBar. the code is correct because i tried it on eclipse 3.4 and it worked fine.This is definitely netbeans error. because its giving error even if u try to execute javafx code with just one ToggleButton or ProgressBar. I tried the following simple code in netbeans 6.5
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.control.ToggleButton;
    import javafx.scene.control.ProgressBar;
    var toggle=ToggleButton {
                    translateX:50
                    translateY:50
                    text: "First"
                    width:100
                    height:20
    var progress= ProgressBar {
            progress: bind ProgressBar.computeProgress( 100, 30 )
    Stage {
        title : "Toggle Button Test"
        scene: Scene {
            width: 200
            height: 200
            content: [ toggle
    } When i just added toggle button to contents then button showed up in window but on clicking it window disappear and compiler gave crash error on the other hand when i added just progess bar it just throws the error.The same code is running fine on eclipse
    Is there any workaround in netbeans for this if its a bug and if not what should i do to correct it.

  • [Urgent] using javafx object in java project

    Suppose I here created a very simple java project and the main file is like below,
    public class test {
        public static void main(String[] args){
                System.out.println("Hello World!");
    }and in this particular java project, I need to use another javafx object which is defined as (the javafx and java file are in the same package),
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Circle;
    var stage: Stage = Stage {
        title: "Declaring Is Easy!"
        scene: Scene {
            width: 300
            height: 250
            content: [
                Circle {
                    centerX: 150  centerY: 120 radius: 80
                    fill: Color.MAROON
                    stroke: Color.INDIANRED
                    strokeWidth: 10.0
                }, //Circle
                Rectangle {
                    x: 25, y: 80 width: 250, height: 80
                    arcWidth: 20 arcHeight: 20
                    fill: Color.web("#6699ff")
                    stroke: Color.web("#003399")
              strokeWidth: 5.0
                } //Rectangle
            ] //Content
        } //Scene
    } //StageSo how could I achieve this?
    Regards.

    Thanks for your reply.
    But would you please elaborate on this sentence: create the fx class using Class.forName("....").newInstance()?
    Indeed I implemented an interface which was extended by the javafx class, and in the main java file I need to write following codes to use this object,
    Context context = FXLocal.getContext();
            FXClassType instance = context.findClass("packageName.JavaFXClass");
            ObjectValue obj = (ObjectValue)instance.newInstance();
            JavaInterface ji = (JavaInterface)obj.asObject();The problem that I encountered right now is, the exception was thrown at context.findClass("javatest.MyChart");, since it's not able for the compiler to find the JavaFXClass.class.
    I checked the folder build\classes\packageName and noticed that both my main JavaClass and JavaInterface have been compiled with .class file, while the JavaFXClass was not, which means the file JavaFXClass.class doesn't exist.
    What's the solution?

  • TableView.edit() is not working in JavaFX 2.1

    Hi All,
    Yesterday i have updated my javafx installation from JavaFX 2.0.2 to JavaFX 2.1 b07
    After that I am facing issues with TableView.edit() method. It stops working and not making the cell as editable.
    In the below example , select the first cell, and on click of 'tab' , the next cell is changed to editing state..and goes on for all the cells. If it reaches the end column, the first cell of the next row is selected.
    You can find the sscce example below. The same code is working well in 2.0.2 build.
    import javafx.application.Application;
    import javafx.beans.property.SimpleStringProperty;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.event.EventHandler;
    import javafx.scene.Node;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.TableCell;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.TextField;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.input.KeyCode;
    import javafx.scene.input.KeyEvent;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    import javafx.util.Callback;
    import com.sun.javafx.scene.control.skin.TableRowSkin;
    public class StartEditDemo extends Application {
        public static void main(String[] args) {
            Application.launch(args);
        public void start(Stage primaryStage) {
            primaryStage.setTitle("Start Edit Test");
            StackPane root = new StackPane();
            Scene scene = new Scene(root, 600, 150);
            primaryStage.setScene(scene);
            primaryStage.show();
            configureTable(root);
         private void configureTable(StackPane root) {
              final ObservableList<MyDomain> data = FXCollections.observableArrayList(
                         new MyDomain("Apple","This is a fruit","Red"),
                         new MyDomain("PineApple","This is also a fruit","Yellow"),
                         new MyDomain("Potato","This is a vegetable","Brown")
              TableView<MyDomain> table = new TableView<MyDomain>();
              TableColumn<MyDomain,String> titleColumn = new TableColumn<MyDomain,String>("Name");
              titleColumn.setPrefWidth(150);
              titleColumn.setCellValueFactory(new PropertyValueFactory<MyDomain,String>("name"));
              titleColumn.setCellFactory(getEditableCallBack(1));
              TableColumn<MyDomain,String> descCol = new TableColumn<MyDomain,String>("Description");
              descCol.setPrefWidth(150);
              descCol.setCellValueFactory(new PropertyValueFactory<MyDomain,String>("description"));
              descCol.setCellFactory(getEditableCallBack(2));
              TableColumn<MyDomain,String> colorCol = new TableColumn<MyDomain,String>("Color");
              colorCol.setPrefWidth(150);
              colorCol.setCellValueFactory(new PropertyValueFactory<MyDomain,String>("color"));
              colorCol.setCellFactory(getEditableCallBack(0));
              table.getColumns().addAll(titleColumn,descCol,colorCol);
              table.setItems(data);
              root.getChildren().add(table);
         private Callback<TableColumn<MyDomain, String>, TableCell<MyDomain, String>> getEditableCallBack(final int nextColumn) {
              /* Cell factory call back object */
              return new Callback<TableColumn<MyDomain, String>, TableCell<MyDomain, String>>() {
                   @Override
                   public TableCell<MyDomain, String> call(TableColumn<MyDomain, String> p) {
                        return new EditableCell<MyDomain>(nextColumn);
         public class EditableCell<T> extends TableCell<T, String> {
              private TextField textBox;
              private Label label;
              private int nextCol;
              public EditableCell(int nextcolumn) {
                   this.label = new Label();
                   this.nextCol = nextcolumn;
                   /* Enabling to get the edit cell on single mouse click over the cell. */
                   this.setOnMouseClicked(new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent event) {
                             startEdit();
              @Override
              public void startEdit() {
                   super.startEdit();
                   if (isEmpty()) {
                        return;
                   if (textBox == null) {
                        createTextBox();
                   } else {
                        textBox.setText(getItem());
                   setGraphic(textBox);
                   textBox.requestFocus();
                   textBox.selectAll();
                   setEditable(true);
              @Override
              public void updateItem(String item, boolean empty) {
                   super.updateItem(item, empty);
                   if (!isEmpty()) {
                        if (textBox != null) {
                             textBox.setText(item);
                        label.setText(item);
                        setGraphic(label);
              private void createTextBox() {
                   textBox = new TextField(getItem());
                   /* On focus of the textbox, selecting the row.*/
                   textBox.focusedProperty().addListener(new ChangeListener<Boolean>() {
                        @Override
                        public void changed(ObservableValue<? extends Boolean> paramObservableValue,Boolean paramT1, Boolean paramT2) {
                             if(paramT2){
                                  EditableCell.this.getTableView().getSelectionModel().select(EditableCell.this.getIndex());
                   textBox.setOnKeyReleased(new EventHandler<KeyEvent>() {
                        @Override
                        public void handle(KeyEvent t) {
                             if (t.getCode() == KeyCode.ENTER) {
                                  callAction();
                             } else if (t.getCode() == KeyCode.ESCAPE) {
                                  cancelEdit();
                   textBox.setOnKeyPressed(new EventHandler<KeyEvent>() {
                        @Override
                        public void handle(KeyEvent t) {
                             if (t.getCode() == KeyCode.TAB){
                                  if(nextCol!=0){
                                       // Making the next as editable and focused.
                                       TableColumn nextColumn = getTableView().getColumns().get(nextCol);
                                       getTableView().edit(getTableRow().getIndex(), nextColumn);
                                       getTableView().getFocusModel().focus(getTableRow().getIndex(), nextColumn);
                                  }else{
                                       // Making the next row as editable.
                                       if(getTableRow().getIndex()<getTableView().getItems().size()){
                                            TableColumn nextColumn = getTableView().getColumns().get(0);
                                            getTableView().edit(getTableRow().getIndex()+1, nextColumn);
                                            getTableView().getFocusModel().focus(getTableRow().getIndex()+1, nextColumn);
              @Override
              public void cancelEdit() {
                   super.cancelEdit();
                   textBox = null;
                   setGraphic(label);
              @Override
              public void commitEdit(String t) {
                   super.commitEdit(t);
                   setItem(t);
                   textBox = null;
                   label.setText(t);
                   setGraphic(label);
              @SuppressWarnings("rawtypes")
              public ObservableList<Node> getAllCellsOfSameRow(TableCell cell) {
                   TableRowSkin rowSkin = (TableRowSkin) cell.getParent();
                   return rowSkin.getChildren();
              public void callAction() {
                   TableRowSkin<T> rowSkin = (TableRowSkin<T>) this.getParent();
                   ObservableList<Node> cells = rowSkin.getChildren();
                   for (Node node : cells) {
                        EditableCell<T> cell = (EditableCell<T>) node;
                        cell.commitEdit(cell.getTextBox().getText());
              public TextField getTextBox() {
                   return this.textBox;
              public Label getLabel() {
                   return this.label;
         public class MyDomain{
              private SimpleStringProperty name = new SimpleStringProperty();
              private SimpleStringProperty description = new SimpleStringProperty();
              private SimpleStringProperty color = new SimpleStringProperty();
              public MyDomain(String name, String desc, String color){
                   this.name.set(name);
                   this.description.set(desc);
                   this.color.set(color);
              public String getDescription() {
                 return description.get();
              public SimpleStringProperty descriptionProperty(){
                  return description;
             public String getName() {
                 return name.get();
             public SimpleStringProperty nameProperty(){
                  return name;
             public String getColor() {
                 return color.get();
             public SimpleStringProperty colorProperty(){
                  return color;
    }Regards,
    Sai Pradeep Dandem.

    As jsmith notes, the best place to report bugs is directly into the Jira tracker at http://javafx-jira.kenai.com. If you put it in the 'runtime' area against the 'controls' component, it'll end up on my plate.
    Thanks!
    Jonathan

  • Play a YouTube video in JavaFX?

    Moderator action: deleted rant and cleaned up what remains.
    I am trying to make this code play an FLV video, and it doesn't show any video. Only Music. How can I convert, for instance, a YouTube video, to play in JavaFX? If I download a YouTube video, how can i encode it?
    package musica;
    import javafx.application.Application;
    import javafx.beans.property.ObjectProperty;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.GridPane;
    import javafx.scene.layout.StackPane;
    import javafx.scene.media.Media;
    import javafx.scene.media.MediaErrorEvent;
    import javafx.scene.media.MediaPlayer;
    import javafx.scene.media.MediaView;
    import javafx.scene.text.Font;
    import javafx.scene.text.FontPosture;
    import javafx.stage.Stage;
    import javafx.util.Duration;
    import javax.swing.Action;
    import javax.swing.JFileChooser;
    import javax.swing.JOptionPane;
    //import javafx.io.http;
    * @author André Lopes
    public class Musica extends Application {
        public MediaPlayer MP;
        public Media Media;
        public static String URL;
        public static JFileChooser JFC;
        public static Duration currentTime;
        public MediaView mediaView;
        //Main
        public static void main(String[] args) {
            launch(args);
        public Musica()
         currentTime = Duration.ZERO;
         mediaView= new MediaView(MP);
           URL = "";
         //URL = "http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv";
        @Override
        public void start(Stage primaryStage) {
            primaryStage.setTitle("Hello! This is Yours Music Player!");
            //Botão Play
            Button Play = new Button();
            Play.setText("Play");
            Play.setOnAction(new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent event1) {
                    Media = new Media(URL);
                    MP = new MediaPlayer(Media);
                    MP.setStartTime(currentTime);
                    mediaView.setMediaPlayer(MP);
                    MP.play();
                    System.out.println("?"+ MP.getStatus());
                    mediaView.setOnError(new EventHandler<MediaErrorEvent>() {
                    @Override
                    public void handle(MediaErrorEvent arg0) {
                                System.out.println("MP.getStatus: " + MP.getStatus());
            //Botão Hello World
            //Botão pra escolher Musica
            Button SelctFileButton = new Button();
            SelctFileButton.setText("Music Chooser/Finder:");
            SelctFileButton.setOnAction(new EventHandler<ActionEvent>() {
                @Override
                  public void handle(ActionEvent arg0) {
                    System.out.println("Java File Chooser Opened");
                    JFileChooser search = new JFileChooser();
                    search.showDialog(search,URL);
                    URL = search.getSelectedFile().toURI().toString();
                    System.out.println("URL:"+URL);
           //Botão para pausar;
           Button Pause = new Button();
           Pause.setText("Pause");
           Pause.setFont(Font.font(null, FontPosture.ITALIC,15));
           Pause.setOnAction(new EventHandler<ActionEvent>() {
           @Override
                public void handle(ActionEvent arg0) {
                try {
                    currentTime = MP.getCurrentTime();
                    MP.pause();  
                    }catch(java.lang.NullPointerException e)
                     System.out.println("java.lang.NullPointerException \n");  
                     System.out.println("Error: Unable To pause! May happens if you didnt have a music Playing!");  
           //Botão Para Continuar;
           Button Continue = new Button();
           Continue.setText("Continue/UnPause");
           Continue.setOnAction(new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent arg0) {
                   //MP.setStartTime(currentTime);
                   MP.pause();
            //Grid ! Layout
            GridPane grid = new GridPane();
            StackPane root = new StackPane();
            grid.setHgap(2);
            grid.setHgap(2);
            grid.setVgap(2);
            Scene Scene = new Scene(root,500,500);
            root.getChildren().add(grid);
            root.getChildren().add(mediaView);
            //Scene.getStylesheets().add(Musica.class.getResource("Musica.css").toExternalForm());
            //grid.getStyleClass().add(Musica.class.getResource("Musica.css").toExternalForm());
            primaryStage.setScene(Scene);
            primaryStage.show();
            //Adicionando Botoes no Grid
            grid.add(Play,10,10);
            grid.add(SelctFileButton,11,10);
            grid.add(Pause,10,11);
    }Edited by: 932269 on 06/05/2012 20:36
    Edited by: 932269 on 06/05/2012 20:37
    Edited by: EJP on 8/05/2012 12:02

    After the question title has been cleaned up, I can see now that it relates to youtube video playback.
    Just embed the youtube html5 video player in a webview and stream video from youtube.
    This will work for videos that youtube has made compatible with their html5 player (about 30% it seems).
    Here is a sample embedding a youtube hosted trailer uploaded by sony pictures.
    import javafx.application.Application;
    import javafx.scene.*;
    import javafx.scene.web.WebView;
    import javafx.stage.Stage;
    public class YouTubePlayer extends Application {
      public static void main(String[] args) throws Exception { launch(args); }
      @Override public void start(final Stage stage) throws Exception {
        final WebView webView = new WebView();
        webView.getEngine().loadContent(
          "<iframe width=\"640\" height=\"390\" src=\"http://www.youtube.com/embed/IyaFEBI_L24\" frameborder=\"0\" allowfullscreen></iframe>"
        stage.setScene(new Scene(webView, 660, 410));
        stage.show();
    }If you have any questions, you can read more about youtube embedding here: https://developers.google.com/youtube/player_parameters

  • Binding a JavaFX variable to a Java class instance variable

    Hi,
    I am pretty new to JavaFX but have been developing in Java for many years. I am trying to develop a JavaFX webservice client. What I am doing is creating a basic scene that displays the data values that I am polling with a Java class that extends Thread. The Java class is reading temperature and voltage from a remote server and storing the response in an instance variable. I would like to bind a JavaFx variable to the Java class instance variable so that I can display the values whenever they change.
    var conn: WebserviceConnection; // Java class that extends Thread
    var response: WebserviceResponse;
    try {
    conn = new WebserviceConnection("some_url");
    conn.start();
    Thread.sleep(10000);
    } catch (e:Exception) {
    e.printStackTrace();
    def bindTemp = bind conn.getResponse().getTemperature();
    def bindVolt = bind conn.getResponse().getVoltage();
    The WebserviceConnection class is opening a socket connection and reading some data in a separate thread. A regular socket connection is used because the server is not using HTTP.
    When I run the application, the bindTemp and bindVolt are not updated whenever new data values are received.
    Am I missing something with how bind works? Can I do what I want to do with 'bind'. I basically want to run a separate thread to retrieve data and want my UI to be updated when the data changes.
    Is there a better way to do this than the way I am trying to do it?
    Thanks for any help in advance.
    -Richard

    Hi,
    If you don't want to constantly poll for value change, you can use the observer design pattern, but you need to modify the classes that serve the values to javafx.
    Heres a simple example:
    The Thread which updates a value in every second:
    // TimeServer.java
    public class TimeServer extends Thread {
        private boolean interrupted = false;
        public ValueObject valueObject = new ValueObject();
        @Override
        public void run() {
            while (!interrupted) {
                try {
                    valueObject.setValue(Long.toString(System.currentTimeMillis()));
                    sleep(1000);
                } catch (InterruptedException ex) {
                    interrupted = true;
    }The ValueObject class which contains the values we want to bind in javafx:
    // ValueObject.java
    import java.util.Observable;
    public class ValueObject extends Observable {
        private String value;
        public String getValue() {
            return this.value;
        public void setValue(String value) {
            this.value = value;
            fireNotify();
        private void fireNotify() {
            setChanged();
            notifyObservers();
    }We also need an adapter class in JFX so we can use bind:
    // ValueObjectAdapter.fx
    import java.util.Observer;
    import java.util.Observable;
    public class ValueObjectAdapter extends Observer {
        public-read var value : String;
        public var valueObject : ValueObject
            on replace { valueObject.addObserver(this)}
        override function update(observable: Observable, arg: Object) {
             // We need to run every code in the JFX EDT
             // do not change if the update method can be called outside the Event Dispatch Thread!
             FX.deferAction(
                 function(): Void {
                    value = valueObject.getValue();
    }And finally the main JFX code which displays the canging value:
    // Main.fx
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.text.Text;
    import javafx.scene.text.Font;
    import threadbindfx.TimeServer;
    var timeServer : TimeServer;
    var valueObjectAdapter : ValueObjectAdapter = new ValueObjectAdapter();
    timeServer = new TimeServer();
    valueObjectAdapter.valueObject = timeServer.valueObject;
    timeServer.start();
    Stage {
        title: "Time Application"
        width: 250
        height: 80
        scene: Scene {
            content: Text {
                font : Font {
                    size : 24
                x : 10, y : 30
                content: bind valueObjectAdapter.value;
    }This approach uses less cpu time than constant polling, and changes aren't dependent on the polling interval.
    However this cannot be applied to code which you cannot change obviously.
    I hope this helps.

Maybe you are looking for

  • How can i use my pictures for Mission Control Spaces in Lion?

    How do I get a chosen selection of my own photos to be available for use as desktop pictures, with a different one for each Space in Mission Control in Lion? I have a new Macbook Air, Thunderbolt display and Lion.

  • Windows 8.1 search not working- program- data missing

    Hi :) I followed the instructions here  http://social.technet.microsoft.com/Forums/windows/en-US/bb1ba41a-80d9-4036-974b-50e81dc99893/windows-81-search-not-working?forum=w8itprogeneral but program-data is not in there Tried searching for how to corre

  • Download to excel from alv display

    Hi, How to download to excel from alv display.I am using object oriented abap for using alv.If i click export->spreadsheet i am getting fatal error and if i export->local file->spreadsheet i am getting only the column names and heading but no content

  • Solaris 8 Intel scan hangs on Windows Sound System Compatable

    I am trying to install Solaris on a Anigma Pentium II motherboard with integrated AGP/Audio/DVD, plextor CDRW, 40 gig maxtor ide hd new, unpartioned..... when the sytem scans it keeps hanging on either "Windows Sound System Compatable" or "ADS Sound

  • Play adds all listed songs to "Selected Mus

    I just purchased a Vision:M. When I go to "All Tracks", highlight a song, and select "Play" from the context menu, ALL the songs are put in the "Selected Music" list. Same goes for "Album", or any other place I select an individual song from, all son