2014-11-21 2 views
0

여기에 문제가 있습니다. 이제JavaFX java.lang.IllegalStateException (Stage)

myps.initStyle(StageStyle.UNDECORATED); // I am trying to create a splash screen look a like 

나는 그래서 나는 이런 식으로 뭔가 할 모든 나의 테두리와 타이틀을 얻기 위해 노력하고 있어요 :의 생각으로

// Exiting splash screen 
myps.hide(); 
myps.initStyle(StageStyle.DECORATED); // (Problem line) 

은 첫 화면에 내 코드입니다 hide()은 내 무대 표시를 보이지 않게 설정하지만 문제는이 오류를 표시합니다.

Cannot set style once stage has been set visible

무대 표시를 보이지 않도록 설정하여 테두리 및 창을 다시 가져올 수있는 방법 ... 또는 어떻게 처리합니까? 또한 나는 어떻게해서든지 새롭기 때문에 JavaFX에 새롭다. 내가 얼마나 정중한지에 대한 정의가있다. ...

답변

1

메시지는 "한 번 단계가 보이게 설정되었습니다."라고 말합니다.

당신이해야 할 일은 새로운 무대를 만드는 것입니다. 자세한 내용은 Designing a splash screen (java)에 대한 내 대답을 볼 수 있습니다. 그리고 일부는 sample code in a gist입니다.이 링크는 요점 링크가 끊어지면 여기에서 복사 해 드리겠습니다.

import javafx.animation.FadeTransition; 
import javafx.application.Application; 
import javafx.beans.property.ReadOnlyObjectProperty; 
import javafx.collections.*; 
import javafx.concurrent.*; 
import javafx.geometry.*; 
import javafx.scene.Scene; 
import javafx.scene.control.*; 
import javafx.scene.effect.DropShadow; 
import javafx.scene.image.*; 
import javafx.scene.layout.*; 
import javafx.stage.*; 
import javafx.util.Duration; 
/** 
* Example of displaying a splash page for a standalone JavaFX application 
*/ 
public class FadeApp extends Application { 
    public static final String APPLICATION_ICON = 
      "http://cdn1.iconfinder.com/data/icons/Copenhagen/PNG/32/people.png"; 
    public static final String SPLASH_IMAGE = 
      "http://fxexperience.com/wp-content/uploads/2010/06/logo.png"; 

    private Pane splashLayout; 
    private ProgressBar loadProgress; 
    private Label progressText; 
    private Stage mainStage; 
    private static final int SPLASH_WIDTH = 676; 
    private static final int SPLASH_HEIGHT = 227; 

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

    @Override 
    public void init() { 
     ImageView splash = new ImageView(new Image(
       SPLASH_IMAGE 
     )); 
     loadProgress = new ProgressBar(); 
     loadProgress.setPrefWidth(SPLASH_WIDTH - 20); 
     progressText = new Label("Will find friends for peanuts . . ."); 
     splashLayout = new VBox(); 
     splashLayout.getChildren().addAll(splash, loadProgress, progressText); 
     progressText.setAlignment(Pos.CENTER); 
     splashLayout.setStyle(
       "-fx-padding: 5; " + 
       "-fx-background-color: cornsilk; " + 
       "-fx-border-width:5; " + 
       "-fx-border-color: " + 
        "linear-gradient(" + 
         "to bottom, " + 
         "chocolate, " + 
         "derive(chocolate, 50%)" + 
        ");" 
     ); 
     splashLayout.setEffect(new DropShadow()); 
    } 

    @Override 
    public void start(final Stage initStage) throws Exception { 
     final Task<ObservableList<String>> friendTask = new Task<ObservableList<String>>() { 
      @Override 
      protected ObservableList<String> call() throws InterruptedException { 
       ObservableList<String> foundFriends = 
         FXCollections.<String>observableArrayList(); 
       ObservableList<String> availableFriends = 
         FXCollections.observableArrayList(
           "Fili", "Kili", "Oin", "Gloin", "Thorin", 
           "Dwalin", "Balin", "Bifur", "Bofur", 
           "Bombur", "Dori", "Nori", "Ori" 
         ); 

       updateMessage("Finding friends . . ."); 
       for (int i = 0; i < availableFriends.size(); i++) { 
        Thread.sleep(400); 
        updateProgress(i + 1, availableFriends.size()); 
        String nextFriend = availableFriends.get(i); 
        foundFriends.add(nextFriend); 
        updateMessage("Finding friends . . . found " + nextFriend); 
       } 
       Thread.sleep(400); 
       updateMessage("All friends found."); 

       return foundFriends; 
      } 
     }; 

     showSplash(
       initStage, 
       friendTask, 
       () -> showMainStage(friendTask.valueProperty()) 
     ); 
     new Thread(friendTask).start(); 
    } 

    private void showMainStage(
      ReadOnlyObjectProperty<ObservableList<String>> friends 
    ) { 
     mainStage = new Stage(StageStyle.DECORATED); 
     mainStage.setTitle("My Friends"); 
     mainStage.getIcons().add(new Image(
       APPLICATION_ICON 
     )); 

     final ListView<String> peopleView = new ListView<>(); 
     peopleView.itemsProperty().bind(friends); 

     mainStage.setScene(new Scene(peopleView)); 
     mainStage.show(); 
    } 

    private void showSplash(
      final Stage initStage, 
      Task<?> task, 
      InitCompletionHandler initCompletionHandler 
    ) { 
     progressText.textProperty().bind(task.messageProperty()); 
     loadProgress.progressProperty().bind(task.progressProperty()); 
     task.stateProperty().addListener((observableValue, oldState, newState) -> { 
      if (newState == Worker.State.SUCCEEDED) { 
       loadProgress.progressProperty().unbind(); 
       loadProgress.setProgress(1); 
       initStage.toFront(); 
       FadeTransition fadeSplash = new FadeTransition(Duration.seconds(1.2), splashLayout); 
       fadeSplash.setFromValue(1.0); 
       fadeSplash.setToValue(0.0); 
       fadeSplash.setOnFinished(actionEvent -> initStage.hide()); 
       fadeSplash.play(); 

       initCompletionHandler.complete(); 
      } // todo add code to gracefully handle other task states. 
     }); 

     Scene splashScene = new Scene(splashLayout); 
     initStage.initStyle(StageStyle.UNDECORATED); 
     final Rectangle2D bounds = Screen.getPrimary().getBounds(); 
     initStage.setScene(splashScene); 
     initStage.setX(bounds.getMinX() + bounds.getWidth()/2 - SPLASH_WIDTH/2); 
     initStage.setY(bounds.getMinY() + bounds.getHeight()/2 - SPLASH_HEIGHT/2); 
     initStage.show(); 
    } 

    public interface InitCompletionHandler { 
     public void complete(); 
    } 
} 
+1

++ 1 나는 생각을위한 음식을주는 것이 아니라 실현을위한 디저트도 주었다. 내가 말한 것이 의미가 있지만, 내가 아는 모든 것이 행복하다면 .. 엘 엘 .. – Elltz