HiddenSidesPane fxml示例

时间:2015-06-23 14:29:17

标签: javafx

任何人都能告诉我如何在FXML中构建HiddenSidesPane而不是在控制器中吗?

我有基本的控制器代码,但是我无法理解如何从中创建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>

1 个答案:

答案 0 :(得分:4)

这是我如何在控制器控制器的官方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>

FXMLController.java

注入变量窗格和pinLabel以设置它们。

import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Side;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import org.controlsfx.control.HiddenSidesPane;

public class FXMLDocumentController implements Initializable {

  @FXML
  private HiddenSidesPane pane;

  @FXML
  private Label pinLabel;

  @FXML
  private void handleMouseClicked(MouseEvent event) {
    if (pane.getPinnedSide() != null) {
      pinLabel.setText("(unpinned)");
      pane.setPinnedSide(null);
    } else {
      pinLabel.setText("(pinned)");
      pane.setPinnedSide(Side.TOP);
    }
  }

  @Override
  public void initialize(URL url, ResourceBundle rb) {
    // TODO
  }

}

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:http://controlsfx.bitbucket.org/org/controlsfx/control/HiddenSidesPane.html

如果你需要一个例子下载Zip http://fxexperience.com/downloads/controlsfx-8.40.9.zip并解压缩它,里面有一个文件controlsfx-samples-8.40.9.jar。双击它并显示来源。