Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javafx 2 JavaFX java.lang.IllegalStateException(阶段)_Javafx 2_Javafx 8 - Fatal编程技术网

Javafx 2 JavaFX java.lang.IllegalStateException(阶段)

Javafx 2 JavaFX java.lang.IllegalStateException(阶段),javafx-2,javafx-8,Javafx 2,Javafx 8,我这里有些问题 这是我在第一个屏幕上的代码: 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) 考虑到hid

我这里有些问题

这是我在第一个屏幕上的代码:

 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()
会将我的舞台可见性设置为不可见,但问题行给出了以下错误:

一旦阶段设置为可见,则无法设置样式

如何将舞台可见性设置为“不可见”,以便恢复边框和窗口。。。或者你是怎么做的?而且,不知何故,我对“我是多么精通”的定义是新的…

正如信息所说,“一旦舞台设置为可见状态,就无法设置风格”

你需要做的是创造一个新的舞台。有关详细信息,请参见我对的答复。还有一些,我会把它们复制到这里,以防主链接失效

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();
    }
}
导入javafx.animation.FadeTransition;
导入javafx.application.application;
导入javafx.beans.property.ReadOnlyObject属性;
导入javafx.collections.*;
导入javafx.concurrent.*;
导入javafx.geometry.*;
导入javafx.scene.scene;
导入javafx.scene.control.*;
导入javafx.scene.effect.DropShadow;
导入javafx.scene.image.*;
导入javafx.scene.layout.*;
导入javafx.stage.*;
导入javafx.util.Duration;
/**
*显示独立JavaFX应用程序启动页的示例
*/
公共类FadeApp扩展了应用程序{
公共静态最终字符串应用程序\u图标=
"http://cdn1.iconfinder.com/data/icons/Copenhagen/PNG/32/people.png";
公共静态最终字符串SPLASH_IMAGE=
"http://fxexperience.com/wp-content/uploads/2010/06/logo.png";
专用窗格布局;
私人进度条加载进度;
私有标签文本;
私人舞台主体;
专用静态最终int SPLASH_宽度=676;
专用静态最终内部飞溅高度=227;
公共静态void main(字符串[]args)引发异常{
发射(args);
}
@凌驾
公共void init(){
ImageView splash=新图像视图(新图像(
飞溅图像
));
loadProgress=newprogressbar();
loadProgress.setPrefWidth(飞溅宽度-20);
progressText=新标签(“将为花生找到朋友…”);
splashLayout=新的VBox();
splashLayout.getChildren().addAll(splash、loadProgress、progressText);
progressText.setAlignment(位置中心);
splashLayout.setStyle(
“-fx填充:5;”+
“-fx背景色:玉米丝;”+
“-fx边框宽度:5;”+
“-fx边框颜色:”+
“线性梯度(”+
“到底,”+
“巧克力,”+
“衍生(巧克力,50%)”+
");"
);
setEffect(新的DropShadow());
}
@凌驾
public void start(final Stage initStage)引发异常{
最终任务friendTask=新任务(){
@凌驾
受保护的ObservableList调用()引发InterruptedException{
观察者朋友=
FXCollections.observableArrayList();
可观测列表可用变量=
FXCollections.observableArrayList(
“菲利”、“基利”、“奥因”、“格洛因”、“托林”,
“德瓦林”、“巴林”、“比弗”、“波弗尔”,
“Bombur”、“Dori”、“Nori”、“Ori”
);
更新消息(“寻找朋友…”);
对于(int i=0;ishowMainStage(friendTask.valueProperty())
);
新线程(friendTask).start();
}
私人虚空展示(
ReadOnlyObjectProperty好友
) {
主舞台=新舞台(舞台风格装饰);
主干.setTitle(“我的朋友”);
mainStage.getIcons().add(新图像(
应用程序图标
));
final ListView peopleView=新建ListView();
peopleView.itemsProperty().bind(朋友);
主舞台。场景(新场景(peopleView));
show();
}
私人空间展示(
最后阶段,,
任务任务,
InitCompletionHandler InitCompletionHandler
) {
progressText.textProperty().bind(task.messageProperty());
loadProgress.progressProperty().bind(task.progressProperty());
task.stateProperty().addListener((ObservalEvalue、oldState、newState)->{
if(newState==Worker.State.successed){
loadProgress.progressProperty().unbind();
loadProgress.setProgress(1);
initStage.toFront();
FadeTransition fadeSplash=新的FadeTransition(持续时间。秒(1.2),飞溅布局);
FadesFlash.setFromValue(1.0);
fadeSplash.setToValue(0.0);
setOnFinished(actionEvent->initStage.hide());
flash.play();
initCompletionHandler.complete();
}//todo添加代码以优雅地处理其他任务状态。
});
场景splashScene=新场景(splashLayout);
initStage.initStyle(StageStyle.UNDECORATED);
最终矩形2D边界=Screen.getPrimary().ge