最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaFX實(shí)現(xiàn)界面跳轉(zhuǎn)

 更新時間:2022年06月16日 16:36:58   作者:西子~  
這篇文章主要為大家詳細(xì)介紹了JavaFX實(shí)現(xiàn)界面跳轉(zhuǎn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

界面跳轉(zhuǎn),很常見的一個功能,在桌面程序中,可以多窗口跳轉(zhuǎn),也可以在一個窗口中跳轉(zhuǎn)。不同方式對應(yīng)不同場景。下面簡單介紹一下,JavaFX中單窗口界面跳轉(zhuǎn)方式。

BorderPane 跳轉(zhuǎn)

利用BorderPane的setCenter重新設(shè)置中心節(jié)點(diǎn)進(jìn)行界面跳轉(zhuǎn)。

好處是其他區(qū)域的節(jié)點(diǎn)不會更新,只會更新center中的節(jié)點(diǎn),并且可以控制是每個頁面是否可以重新加載,方便。

scene節(jié)點(diǎn)如下,在BorderPane的top中設(shè)置按鈕事件,更新center。

fxml

<BorderPane prefHeight="200.0" prefWidth="200.0" fx:id="container">
? ? ? ? ?<top>
? ? ? ? ? ? <HBox alignment="CENTER" spacing="20.0" BorderPane.alignment="CENTER">
? ? ? ? ? ? ? ?<children>
? ? ? ? ? ? ? ? ? <Button mnemonicParsing="false" text="首頁" onAction="#toHome" />
? ? ? ? ? ? ? ? ? <Button mnemonicParsing="false" text="文件" onAction="#toFile"/>
? ? ? ? ? ? ? ? ? <Button mnemonicParsing="false" text="設(shè)置" onAction="#toSetting"/>
? ? ? ? ? ? ? ?</children>
? ? ? ? ? ? ? ?<padding>
? ? ? ? ? ? ? ? ? <Insets bottom="10.0" top="10.0" />
? ? ? ? ? ? ? ?</padding>
? ? ? ? ? ? </HBox>
? ? ? ? ?</top>
? ? ? ? ?<center>
? </center>
</BorderPane>

controller

public class JumpController {

? ? public BorderPane container;

? ? public void initialize() {
? ? ? ? URL resource = getClass().getResource("/fxml/jump/home.fxml");
? ? ? ? try {
? ? ? ? ? ? setCenter(resource);
? ? ? ? } catch (IOException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? }

? ? private void setCenter(URL url) throws IOException {
? ? ? ? FXMLLoader loader = new FXMLLoader(url);
? ? ? ? loader.load();
? ? ? ? Parent root = loader.getRoot();
? ? ? ? container.setCenter(root);
? ? }

? ? public void toHome(ActionEvent event) {
? ? ? ? URL resource = getClass().getResource("/fxml/jump/home.fxml");
? ? ? ? try {
? ? ? ? ? ? setCenter(resource);
? ? ? ? } catch (IOException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? }

? ? public void toFile(ActionEvent event) {
? ? ? ? URL resource = getClass().getResource("/fxml/jump/file.fxml");
? ? ? ? try {
? ? ? ? ? ? setCenter(resource);
? ? ? ? } catch (IOException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? }

? ? public void toSetting(ActionEvent event) {
? ? ? ? URL resource = getClass().getResource("/fxml/jump/setting.fxml");
? ? ? ? try {
? ? ? ? ? ? setCenter(resource);
? ? ? ? } catch (IOException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? }
}

StackPane跳轉(zhuǎn)

StackPane也是JavaFX中的一個面板容器,特點(diǎn)是里面的元素是堆疊在一起的,每次只顯示最上層元素。利用這個特點(diǎn),可以把多個界面加載之后作為StackPane的字節(jié)的,然后調(diào)整StackPane的頂層元素即可。

這種方法比較適合每個頁面跳轉(zhuǎn)時不需要重新加載的情況,效率比較高,只是改變字節(jié)點(diǎn)的順序。

fxml

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="529.0" prefWidth="785.0"
? ? ? xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="xyz.yuelai.controller.Jump1Controller">
? ?<HBox alignment="CENTER" spacing="20.0">
? ? ? <children>
? ? ? ? ?<Button mnemonicParsing="false" onAction="#toHome" text="首頁" />
? ? ? ? ?<Button mnemonicParsing="false" onAction="#toFile" text="文件" />
? ? ? ? ?<Button mnemonicParsing="false" onAction="#toSetting" text="設(shè)置" />
? ? ? </children>
? ? ? <padding>
? ? ? ? ?<Insets bottom="10.0" top="10.0" />
? ? ? </padding>
? ?</HBox>
? ?<StackPane prefHeight="150.0" prefWidth="200.0" VBox.vgrow="ALWAYS" fx:id="container" />

</VBox>

controller

public class Jump1Controller {

? ? public StackPane container;
? ? private Parent home;
? ? private Parent file;
? ? private Parent setting;

? ? public void initialize() {
? ? ? ? try {
? ? ? ? ? ? URL homeUrl = getClass().getResource("/fxml/jump/home.fxml");
? ? ? ? ? ? home = getParent(homeUrl);
? ? ? ? ? ? URL fileUrl = getClass().getResource("/fxml/jump/file.fxml");
? ? ? ? ? ? file = getParent(fileUrl);
? ? ? ? ? ? URL settingUrl = getClass().getResource("/fxml/jump/setting.fxml");
? ? ? ? ? ? setting = getParent(settingUrl);

? ? ? ? ? ? container.getChildren().addAll(setting, file, home);
? ? ? ? } catch (IOException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? }

? ? private Parent getParent(URL url) throws IOException {
? ? ? ? FXMLLoader loader = new FXMLLoader(url);
? ? ? ? return loader.load();
? ? }

? ? public void toHome(ActionEvent event) {
? ? ? ? home.toFront();
? ? }

? ? public void toFile(ActionEvent event) {
? ? ? ? file.toFront();
? ? }

? ? public void toSetting(ActionEvent event) {
? ? ? ? setting.toFront();
? ? }
}

三個界面的fxml如下:

首頁

<AnchorPane prefHeight="460.0" prefWidth="781.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
? ?<children>
? ? ? <Label alignment="CENTER" layoutX="297.0" layoutY="131.0" prefHeight="110.0" prefWidth="129.0" style="-fx-background-color: #a00;" text="首頁" textFill="WHITE" AnchorPane.leftAnchor="200.0" AnchorPane.rightAnchor="200.0" AnchorPane.topAnchor="100.0">
? ? ? ? ?<font>
? ? ? ? ? ? <Font name="System Bold" size="20.0" />
? ? ? ? ?</font>
? ? ? </Label>
? ?</children>
</AnchorPane>

文件

<AnchorPane prefHeight="460.0" prefWidth="781.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
? ? <children>
? ? ? ? <Label alignment="CENTER" layoutX="297.0" layoutY="131.0" prefHeight="110.0" prefWidth="129.0" style="-fx-background-color: #0a0;" text="文件" textFill="WHITE" AnchorPane.leftAnchor="200.0" AnchorPane.rightAnchor="200.0" AnchorPane.topAnchor="100.0">
? ? ? ? ? ? <font>
? ? ? ? ? ? ? ? <Font name="System Bold" size="20.0" />
? ? ? ? ? ? </font>
? ? ? ? </Label>
? ? </children>
</AnchorPane>

設(shè)置

<AnchorPane prefHeight="460.0" prefWidth="781.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
? ? <children>
? ? ? ? <Label alignment="CENTER" layoutX="297.0" layoutY="131.0" prefHeight="110.0" prefWidth="129.0" style="-fx-background-color: #00a;" text="設(shè)置" textFill="WHITE" AnchorPane.leftAnchor="200.0" AnchorPane.rightAnchor="200.0" AnchorPane.topAnchor="100.0">
? ? ? ? ? ? <font>
? ? ? ? ? ? ? ? <Font name="System Bold" size="20.0" />
? ? ? ? ? ? </font>
? ? ? ? </Label>
? ? </children>
</AnchorPane>

其他跳轉(zhuǎn)方式,比如重新設(shè)置scene,這就相當(dāng)于重新加載當(dāng)前窗口,如非必要還是不推薦。上面兩種方式都是操作的容器里面的節(jié)點(diǎn)。實(shí)現(xiàn)了視覺上的界面跳轉(zhuǎn)。所以不局限于BorderPane和StackPane,只是這兩個容器用起來比較方便。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot使用AOP統(tǒng)一日志管理的方法詳解

    SpringBoot使用AOP統(tǒng)一日志管理的方法詳解

    這篇文章主要為大家分享一個干貨:超簡潔SpringBoot使用AOP統(tǒng)一日志管理,文中的示例代碼講解詳細(xì),感興趣的小伙伴快跟隨小編一起學(xué)習(xí)學(xué)習(xí)吧
    2022-05-05
  • Lambda表達(dá)式的使用及注意事項

    Lambda表達(dá)式的使用及注意事項

    這篇文章主要介紹了Lambda表達(dá)式的使用及注意事項,主要圍繞?Lambda表達(dá)式的省略模式?Lambda表達(dá)式和匿名內(nèi)部類的區(qū)別的相關(guān)內(nèi)容展開詳情,感興趣的小伙伴可以參考一下
    2022-06-06
  • SpringBoot啟動時如何通過啟動參數(shù)指定logback的位置

    SpringBoot啟動時如何通過啟動參數(shù)指定logback的位置

    這篇文章主要介紹了SpringBoot啟動時如何通過啟動參數(shù)指定logback的位置,在spring boot中,使用logback配置的方式常用的有兩種,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2023-07-07
  • Kafka中使用Avro序列化和反序列化詳解

    Kafka中使用Avro序列化和反序列化詳解

    這篇文章主要介紹了Kafka中使用Avro序列化和反序列化詳解,由于Kafka中的數(shù)據(jù)都是字節(jié)數(shù)組,在將消息發(fā)送到Kafka之前需要先將數(shù)據(jù)序列化為字節(jié)數(shù)組, 序列化器的作用就是用于序列化要發(fā)送的消息的,需要的朋友可以參考下
    2023-12-12
  • Spring使用@Autowired注解靜態(tài)實(shí)例對象方式

    Spring使用@Autowired注解靜態(tài)實(shí)例對象方式

    這篇文章主要介紹了Spring使用@Autowired注解靜態(tài)實(shí)例對象方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • Java實(shí)現(xiàn)根據(jù)模板讀取PDF并替換指定內(nèi)容

    Java實(shí)現(xiàn)根據(jù)模板讀取PDF并替換指定內(nèi)容

    在實(shí)際開發(fā)里,經(jīng)常會遇到需要根據(jù)?PDF?模板文檔生成特定?PDF?的需求,本文將利用Java中的iText實(shí)現(xiàn)讀取?PDF?模板文檔并替換指定內(nèi)容,最后重新生成新PDF,感興趣的可以了解下
    2025-02-02
  • Java獲取支付寶OpenID的實(shí)現(xiàn)方法

    Java獲取支付寶OpenID的實(shí)現(xiàn)方法

    在Java中,通過支付寶開放平臺API可以獲取用戶的OpenID,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-09-09
  • Springboot Cucumber測試配置介紹詳解

    Springboot Cucumber測試配置介紹詳解

    這篇文章主要介紹了Springboot Cucumber測試配置介紹詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-04-04
  • Java設(shè)計模式以虹貓藍(lán)兔的故事講解適配器模式

    Java設(shè)計模式以虹貓藍(lán)兔的故事講解適配器模式

    適配器模式(Adapter?Pattern)是作為兩個不兼容的接口之間的橋梁。這種類型的設(shè)計模式屬于結(jié)構(gòu)型模式,它結(jié)合了兩個獨(dú)立接口的功能
    2022-04-04
  • mybatis升級mybatis-plus時踩到的一些坑

    mybatis升級mybatis-plus時踩到的一些坑

    這篇文章主要給大家介紹了關(guān)于mybatis升級mybatis-plus時踩到的一些坑,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09

最新評論

辉南县| 绥中县| 三门峡市| 称多县| 太和县| 肥东县| 淮阳县| 景谷| 台东市| 林西县| 洛阳市| 筠连县| 天气| 安福县| 榆林市| 新兴县| 福州市| 夹江县| 盐池县| 黄浦区| 胶州市| 永新县| 丰城市| 新田县| 鄂州市| 贡觉县| 仲巴县| 广丰县| 荣成市| 金川县| 奉贤区| 哈巴河县| 运城市| 东乌珠穆沁旗| 敦化市| 石家庄市| 越西县| 胶南市| 柳河县| 马龙县| 海门市|