javafx如何实现模态/模式对话框
来源:互联网 发布:销售数据分析怎么写 编辑:程序博客网 时间:2024/06/03 11:05
注:打开的模式对话框内是一个嵌套的html页面。(个人需求,和模式对话框没什么关系)
一、模式对话框代码:
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.paint.Color;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Modality;
import javafx.stage.Stage;
public class ModalDialog extends Application {
/**
* 网页地址
*/
private String url;
public ModalDialog(final Stage stg, String url) {
this.url = url;
final Stage stage = new Stage();
// Initialize the Stage with type of modal
stage.initModality(Modality.APPLICATION_MODAL);
// Set the owner of the Stage
stage.initOwner(stg);
stage.setTitle("Top Stage With Modality");
Group root = new Group();
Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN);
stage.setScene(scene);
stage.setTitle("测试页面");
try {
start(stage);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
stage.show();
}
@Override
public void start(Stage stage) throws Exception {
// TODO Auto-generated method stub
stage.setWidth(600);
stage.setHeight(700);
stage.setTitle("测试页面");
Scene scene = new Scene(new Group());
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(browser);
webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == Worker.State.SUCCEEDED) {
}
}
});
webEngine.load(url);
scene.setRoot(scrollPane);
stage.setScene(scene);
stage.show();
}
}
二、调用代码:
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class ModalTest extends Application {
/** * @param args the command line arguments */
public static void main(String[] args) {
Application.launch(ModalTest.class, args);
}
@Override
public void start(final Stage primaryStage) {
primaryStage.setTitle("Hello World");
Group root = new Group();
Scene scene = new Scene(root, 900, 700, Color.LIGHTBLUE);
Button btn = new Button();
btn.setLayoutX(250);
btn.setLayoutY(240);
btn.setText("Show modal dialog");
btn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
ModalDialog md = new ModalDialog(primaryStage,"www.baidu.com");
}
});
root.getChildren().add(btn);
primaryStage.setScene(scene);
primaryStage.show();
}
}
- javafx如何实现模态/模式对话框
- JavaFX如何实现模态窗口
- Android如何实现模态对话框
- cocos2d]如何实现模态对话框
- div层,实现模式窗口/模态窗口/模式对话框
- JavaFX:对话框 Alert
- JavaFX Dialog对话框
- JavaFX之对话框
- javafx模态窗口
- 关于无模式对话框唯一性如何实现
- 在Java applet中如何实现一个模式对话框?
- 如何实现非模式对话框总是浮在屏幕…
- JS 如何实现模态对话框(QQ风格)
- [cocos2d]如何实现模态对话框
- [cocos2d]如何实现模态对话框
- [cocos2d]如何实现模态对话框
- [cocos2d]如何实现模态对话框
- cocos2d-x 中layer如何实现模态对话框
- Ubuntu14.10下LAMP的环境配置
- TransactionProxyFactoryBean 代理事务 $Proxy9 cannot be cast to异常解决方法
- NDK实现的加密/解密库-Codec
- Dialog 和 RecyclerView 一起用
- C++重要性质01:封装(Encapsulation)
- javafx如何实现模态/模式对话框
- mongodb获取具体某一天的查询语句
- 第五周 项目4 长方形类
- c++实验三-个人所得税计算器
- win10激活
- Gradle入门
- 使用python3自带工具2to3.py 转换 python2.x 代码 到python3
- 第七届ccf认证第四题 自己写的错误答案
- 特别关键字