Javafx Hiddensepane fxml示例

Javafx Hiddensepane fxml示例,javafx,Javafx,有人能告诉我如何在FXML中而不是在控制器中构造HiddensedSpane吗 我有这方面的基本控制器代码,但我无法理解如何从中创建fxml结构 我可以要这样的吗?以下代码 <HiddenSidesPane prefWidth="800.0" pinnedSide="TOP"> <content> <HBox fillHeight="false" nodeOrientation="RIGHT_TO_LEFT"

有人能告诉我如何在FXML中而不是在控制器中构造HiddensedSpane吗

我有这方面的基本控制器代码,但我无法理解如何从中创建fxml结构

我可以要这样的吗?以下代码

<HiddenSidesPane prefWidth="800.0" pinnedSide="TOP">
            <content>
                <HBox fillHeight="false" nodeOrientation="RIGHT_TO_LEFT"
                    prefHeight="27.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0"
                    AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
                    AnchorPane.topAnchor="3.0" StackPane.alignment="TOP_RIGHT">
                    <children>
                        <Label prefHeight="14.0" prefWidth="94.0" text="Value Date From">
                            <HBox.margin>
                                <Insets right="2.0" top="5.0" />
                            </HBox.margin>
                        </Label>
                    </children>
                    <StackPane.margin>
                        <Insets top="2.0" />
                    </StackPane.margin>
                </HBox>
            </content>
        </HiddenSidesPane>

下面是我如何利用ControlsFXX的官方FXSampler制作一个快速示例的过程:

假设 您已经设置了FXML项目,并在构建路径上添加了ControlsFX.jar作为依赖项

FXMLDocument.fxml 注意导入语句

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.*?>
<?import org.controlsfx.control.*?>


<StackPane xmlns:fx="http://javafx.com/fxml/1" prefHeight="200" prefWidth="320"  fx:controller="javafxapplication17.FXMLDocumentController">
  <children>
    <HiddenSidesPane fx:id="pane">
      <content>
        <Label alignment="CENTER"  style="-fx-background-color: white; -fx-border-color: black;" maxHeight="1000.0" maxWidth="1000.0"  text="Content Node" />
      </content>
      <top>
        <Label fx:id="pinLabel"  style="-fx-background-color: rgba(0,255,0,.25);"  text="(Click to pin / unpin)" alignment="CENTER" prefHeight="50.0" prefWidth="50.0"  onMouseClicked="#handleMouseClicked"  />
      </top>
    </HiddenSidesPane>
  </children>
</StackPane>
JavaFXApplication17.java 对不起,这个名字:-

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class JavaFXApplication17 extends Application {

  @Override
  public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));

    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.show();
  }

  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
    launch(args);
  }
}
据您所知,这里是HiddenSidesPane的JavaDoc:


如果您需要一个示例,请下载Zip并解压缩,其中有一个文件controlsfx-samples-8.40.9.jar。双击它并显示源。

那么您想在场景生成器中创建HiddensedSpane吗?如果不想从scenebuilder中添加结构,我可以像问题文件中那样在fxml中添加结构吗?问题中添加的FXML代码请检查。您想创建一个侧窗格,在单击按钮或鼠标悬停等时隐藏/显示,还是想特别使用此功能?@Sarfaraz您的回答是同一个问题。Dirk Lemmermann编写了控件并将其推送到controlsfx,就像他在这里解释的那样:没有任何文字只是对您的工作表示赞赏。谢谢你,兄弟。我这里有一个问题。如何推动其他内容?这意味着,如果我在hbox旁边有HiddenSidesPane,当窗格出现时,hbox应该向右移动或在其消失时收缩。嗯,正如我所理解的HiddenSidesPane,它只像覆盖层一样工作,不会移动其内容。是的,我可以理解。Thnq。
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class JavaFXApplication17 extends Application {

  @Override
  public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));

    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.show();
  }

  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
    launch(args);
  }
}