2014-04-10 4 views
1

장면이 다시 칠하기를 기다릴 수있는 방법이 있습니까?장면 다시 채우기 대기

내 문제는 getChildren(). add()를 사용하여 창에 메모를 추가하고 Node.fireEvent (이벤트)를 사용하여이 노드의 이벤트를 발생시키려는 것입니다.

하지만 이벤트가 수행되지 않습니다. 문제는 fireevent 시점에서 장면이 다시 그려지지 않았기 때문에 노드가 이번에 새 장면에 포함되지 않는다는 것입니다.

그래서 가장 좋은 방법은 장면을 다시 칠하기를 기다렸다가 내가 생각하는 이벤트를 시작하는 것입니다.

답변

0

여기에 사용 된 UI 구성 요소가 무엇인지 모르겠지만, 구성 요소의 invalidate() 메소드 (또는 이와 비슷한 것)를 찾아서 화면을 업데이트하도록하십시오.

-1

코드를 게시 할 수 있습니까? 나를 위해 잘 작동합니다 :

import javafx.application.Application; 
import javafx.event.ActionEvent; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.layout.HBox; 
import javafx.stage.Stage; 

public class NewNodeEventTest extends Application { 

    @Override 
    public void start(Stage primaryStage) { 
     HBox root = new HBox(5); 
     Button newNodeButton = new Button("Add button"); 
     newNodeButton.setOnAction(event -> { 
      Button newButton = new Button("Button"); 
      newButton.setOnAction(e -> System.out.println("New button pressed")); 
      root.getChildren().add(newButton); 
      ActionEvent evt = new ActionEvent(newButton, newButton); 
      newButton.fireEvent(evt); 
     }); 
     root.getChildren().add(newNodeButton); 

     Scene scene = new Scene(root, 250, 100); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 
관련 문제