2013-04-01 6 views
1

는이 같은 일부 로딩 점을 만들고 싶어요 :자바 FX 2 동적 도트 로딩

At 0 second the text on the screen is: Loading. 
At 1 second the text on the screen is: Loading.. 
At 2 second the text on the screen is: Loading... 
At 3 second the text on the screen is: Loading. 
At 4 second the text on the screen is: Loading.. 
At 5 second the text on the screen is: Loading... 

을 등 I는 Stage을 닫을 때까지.

JavaFX에서 가장 쉽고/간편한 방법은 무엇입니까? 나는 JavaFX에서 애니메이션/프리 로더를 조사해 왔지만이를 달성하려고 할 때 복잡해 보입니다. 내가 사이에 루프를 만들려고했습니다

이 세 Text :

Text dot = new Text("Loading."); 
Text dotdot = new Text("Loading.."); 
Text dotdotdot = new Text("Loading..."); 

하지만 화면이 정적 유지 ...

가 어떻게이 작품은 자바 FX 제대로 만들 수 있습니까? 감사.

답변

4

이 질문은 비슷하다 javafx animation looping.

JavaFX animation framework을 사용하는 해결책은 다음과 같습니다.

loading animation

import javafx.animation.*; 
import javafx.application.Application; 
import javafx.event.*; 
import javafx.scene.*; 
import javafx.scene.control.Label; 
import javafx.scene.layout.VBox; 
import javafx.stage.Stage; 
import javafx.util.Duration; 

/** Simple Loading Text Animation. */ 
public class DotLoader extends Application { 
    @Override public void start(final Stage stage) throws Exception { 
    final Label status = new Label("Loading"); 
    final Timeline timeline = new Timeline(
     new KeyFrame(Duration.ZERO, new EventHandler() { 
     @Override public void handle(Event event) { 
      String statusText = status.getText(); 
      status.setText(
      ("Loading . . .".equals(statusText)) 
       ? "Loading ." 
       : statusText + " ." 
     ); 
     } 
     }), 
     new KeyFrame(Duration.millis(1000)) 
    ); 
    timeline.setCycleCount(Timeline.INDEFINITE); 

    VBox layout = new VBox(); 
    layout.getChildren().addAll(status); 
    layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;"); 
    stage.setScene(new Scene(layout, 50, 35)); 
    stage.show(); 

    timeline.play(); 
    } 

    public static void main(String[] args) throws Exception { launch(args); } 
} 
+0

매우 유용합니다, 감사합니다! –

0

진행률 표시기 또는 진행률 표시 줄을 사용 해본 적이 있습니까? 나는 그들이 애니메이션을 보여주고 문제를 피하는 좋은 해결책이 될 수 있다고 생각한다.

나는 Animation이 아니라 JavaFX의 동시성 클래스를 사용하여 JavaFX에서이 작업을 수행 할 수있었습니다.

코드는 여기 in a gist입니다. 나는 진도 표시기를 선호하기 때문에 매우 직관적이지 않다고 생각합니다. 그리고 아마도 이것이 최선의 해결책은 아니지만 어쩌면 이것이 당신을 도울 것입니다.

건배