1.禁止窗体缩放
primaryStage.setResizable(true);//禁止窗体缩放
2.去掉窗体边框(包括关闭、最大化、最小化按钮等等)
primaryStage.initStyle(StageStyle.UNDECORATED);
3.加载使用FXML文件
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("fxml/Main.fxml"));//getClass().getClassLoader().getResource() 和 getClass().getResource()的区别,在不在根目录下
4.宽度自适应绑定
menuBar.prefWidthProperty().bind(pane.widthProperty());//MenuBar控件宽度绑定与Pane布局宽度,宽度随窗口缩放
5.TableView控件绑定数据
List spiderList=new ArrayList();
spiderList.add(new Spider(1,"百度","最大的中文搜索引擎","https://www.baidu.com"));
spiderList.add(new Spider(2,"百度2","最大的中文搜索引擎2","https://www.baidu.com2https://www.baidu.comhttps://www.baidu.comhttps://www.baidu.com"));
spiderList.add(new Spider(3,"百度3","最大的中文搜索引擎3","https://www.baidu.com3"));
spiderList.add(new Spider(4,"百度4","最大的中文搜索引擎4","https://www.baidu.com4"));
ObservableList observableList= FXCollections.observableList(spiderList);
tableView.setItems(observableList);
6.新弹出窗口在最上层且不可点击原先窗口
stage.initModality(Modality.APPLICATION_MODAL);
stage.showAndWait();
7.弹出新的窗体(直接掉用这个类的这个方法即可弹出新窗体)
public class NewStage {
public static void showStage() {
Stage stage=new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
Pane pane= null;
try {
pane = FXMLLoader.load(NewStage.class.getResource("newStage.fxml"));
} catch (IOException e) {
e.printStackTrace();
}
Scene scene=new Scene(pane,300,150);
stage.setScene(scene);
stage.showAndWait();
}
}
8.切换新的场景(窗体设置哪个场景就切换场景)
Scene scene1=new Scene(pane,300,150);
Scene scene2=new Scene(pane,300,150);
primaryStage.setScene(scene1);//切换场景1
primaryStage.setScene(scene2);//切换场景2
9.FXML与Controller事件绑定
public void toastBtn(ActionEvent event){
SystemToast.toast();
}
10.最小化
stage.setIconified(true);
11.全屏
stage.setFullScreen(true);
12.悬浮在所有窗体最顶层
stage.setAlwaysOnTop(true);
13.获取屏幕分辨率
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();//获取屏幕宽度高度
primaryScreenBounds.getWidth();//屏幕宽度
primaryScreenBounds.getHeight();//屏幕高度
待续...........