动态更新JFX中的borderpane?

时间:2015-07-20 05:35:50

标签: javafx

我添加了一个包含javafx场景文本的边框。

如何更新javafx中的场景?

我想这样做,以便我可以动态地反映变化。

所以样本看起来像这样:

我的gui:文字

动态更新

我的gui:更新文字

public class JFXPnlRef extends JFXPanel {
   public JFXPnlRef(){
      this.init();
   }
   private void init(){
       Platform.setImplicitExit(false);
       /* run gui main scene */
       Platform.runLater(new Runnable(){
           @Override
           public void run(){
               createScene();
           }  
       });
    }
    private void createScene(){
       /* we are in the JFX thread */
       /* set our look and feel style for the gui */
       borderPane = new BorderPane();
       final Text text = new Text();
       text.setFont(new Font(25));
       text.setText("javafx threads!");
       borderPane.setLeft(text);
       scene = new Scene(borderPane);
       this.setScene(scene);
    }
    public void myThread(){
        JFXPnlThrd.run( new Runnable() {
        @Override
        public void run() {
            final Text text = new Text();
            text.setFont(new Font(25));
            text.setText("inside the thread!");

            scene.getRoot().getChildrenUnmodifiable();
            Parent root = scene.getRoot();
            ObservableList<Node> i = root.getChildrenUnmodifiable();

            /* use the root node to add stuff to the border pane ? */

            revalidate();
            repaint();
            updateUI();
           }
       }); //end of thread
     }//end of method
}//end of class



/ * outter class to check  if we are in the javafx thread */
public class JFXPnlThrd {

     public static void run(Runnable task) {
       if(task == null) 
           throw new IllegalArgumentException(
                   "The task can not be null");
       if(Platform.isFxApplicationThread()) task.run();
       else Platform.runLater(task);
     }
}

1 个答案:

答案 0 :(得分:0)

谢谢ItachiUchiha!

答案很简单。

移动定义为

的本地Text
final Text text = new Text();

到类实例变量

private Text text;