在弹出窗口javafx中使用模态
我在窗格上保留了一个弹出对话框,它位于其他组件的顶部。现在我想禁用访问程序的所有其他组件。怎么做 API没有在弹出窗口javafx中使用模态,javafx,modality,Javafx,Modality,我在窗格上保留了一个弹出对话框,它位于其他组件的顶部。现在我想禁用访问程序的所有其他组件。怎么做 API没有初始化模态(模态.APPLICATION\u模态)方法,这正是您想要的。在这种情况下,您可以将弹出窗口设为阶段并使用上述方法。这是解决方案中的@Xsleek示例代码:- package popupexample; import java.text.SimpleDateFormat; import java.util.Date; import javafx.application.Appl
初始化模态(模态.APPLICATION\u模态)代码>方法,这正是您想要的。在这种情况下,您可以将弹出窗口设为阶段并使用上述方法。这是解决方案中的@Xsleek
示例代码:-
package popupexample;
import java.text.SimpleDateFormat;
import java.util.Date;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBoxBuilder;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
/**
*
* @author reegan
*/
public class PopUpExample extends Application {
@Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
popupErrorMsg();
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
public void popupErrorMsg() {
final Stage myDialog = new Stage();
myDialog.initModality(Modality.APPLICATION_MODAL);
Button okButton = new Button("Ok");
okButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
myDialog.close();
}
});
Date todayDate = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Scene myDialogScene = new Scene(VBoxBuilder.create()
.children(new Text("Please Enter Validate Date \n \t "+ dateFormat.format(todayDate)), okButton)
.spacing(30)
.alignment(Pos.CENTER)
.padding(new Insets(10))
.build());
myDialog.setScene(myDialogScene);
myDialog.show();
}
}
包弹出示例;
导入java.text.simpleDataFormat;
导入java.util.Date;
导入javafx.application.application;
导入javafx.event.ActionEvent;
导入javafx.event.EventHandler;
导入javafx.geometry.Insets;
导入javafx.geometry.Pos;
导入javafx.scene.scene;
导入javafx.scene.control.Button;
导入javafx.scene.layout.StackPane;
导入javafx.scene.layout.VBoxBuilder;
导入javafx.scene.text.text;
导入javafx.stage.model;
导入javafx.stage.stage;
/**
*
*@作者reegan
*/
公共类PopUpExample扩展了应用程序{
@凌驾
公共无效开始(阶段primaryStage){
按钮btn=新按钮();
btn.setText(“说‘你好,世界’”);
btn.setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(ActionEvent事件){
popuperormsg();
}
});
StackPane root=新的StackPane();
root.getChildren().add(btn);
场景=新场景(根,300,250);
setTitle(“你好,世界!”);
初级阶段。场景(场景);
primaryStage.show();
}
/**
*在正确部署的JavaFX应用程序中忽略main()方法。
*main()仅在应用程序无法运行时用作回退
*通过部署工件启动,例如在具有有限FX的IDE中
*support.NetBeans忽略main()。
*
*@param指定命令行参数
*/
公共静态void main(字符串[]args){
发射(args);
}
public void popuperormsg(){
最终阶段myDialog=新阶段();
myDialog.initmodula(modula.APPLICATION_modula);
按钮Ok按钮=新按钮(“Ok”);
setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(ActionEvent arg0){
myDialog.close();
}
});
Date todayDate=新日期();
SimpleDataFormat dateFormat=新的SimpleDataFormat(“dd/MM/yyyy”);
场景myDialogScene=新场景(VBoxBuilder.create()
.children(新文本(“请输入验证日期\n\t”+dateFormat.format(todayDate)),OK按钮)
.间距(30)
.校准(位置中心)
.衬垫(新插图(10))
.build());
myDialog.setScene(myDialogScene);
myDialog.show();
}
}
我也有同样的问题。。。试试这个,这是个好问题。我知道所有给出的答案。但这似乎是popup类的一个重大错误。如果你不能设置它的模态,弹出窗口有什么用??我不想为一个简单的模态输入创建一个新的“阶段”。我喜欢java。但这很奇怪。。。