我正在爲使用JavaFX的學校項目編寫程序。我正在設計SceneBuilder 8中的UI,併爲我生成FXML。我的問題是,如何將我的按鈕和滑塊連接到我的java代碼?是否像XCode中的按鈕編碼?如何使FXML生成的按鈕有效
這裏是我的FXML源,如果有幫助:
<?import javafx.scene.effect.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<SplitPane dividerPositions="0.3996655518394649" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="470.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="398.0" prefWidth="145.0">
<children>
<TableView layoutY="33.0" prefHeight="323.0" prefWidth="180.0" AnchorPane.bottomAnchor="42.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="33.0">
<columns>
<TableColumn prefWidth="77.0" text="Event" />
<TableColumn prefWidth="101.0" text="Suggested time" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<effect>
<Blend />
</effect>
</TableView>
<Label layoutY="6.0" prefHeight="27.0" prefWidth="90.0" text="Event view">
<font>
<Font size="18.0" />
</font>
</Label>
<Button layoutY="368.0" mnemonicParsing="false" prefHeight="0.0" prefWidth="34.0" text="+">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Button>
</children></AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="398.0" prefWidth="267.0">
<children>
<Label layoutY="7.0" prefHeight="27.0" prefWidth="90.0" text="Detail view">
<font>
<Font size="18.0" />
</font>
</Label>
<GridPane layoutX="14.0" layoutY="34.0" prefHeight="120.0" prefWidth="258.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="124.0" minWidth="10.0" prefWidth="87.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="176.0" minWidth="10.0" prefWidth="171.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="75.0" minHeight="10.0" prefHeight="59.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="60.0" minHeight="10.0" prefHeight="31.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="25.0" minHeight="0.0" prefHeight="0.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Name" />
<Label text="Details" GridPane.rowIndex="1" />
<Label text="Estimated time" GridPane.rowIndex="2" />
<TextField promptText="Enter name" GridPane.columnIndex="1" />
<TextField promptText="Enter estimated time" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextArea prefHeight="200.0" prefWidth="200.0" promptText="Enter details" GridPane.columnIndex="1" GridPane.rowIndex="1" />
</children>
</GridPane>
<Button layoutX="219.0" layoutY="372.0" mnemonicParsing="false" text="Done" />
<Button layoutX="152.0" layoutY="372.0" mnemonicParsing="false" text="Cancel" />
</children></AnchorPane>
</items>
</SplitPane>
感謝您的幫助,您可以給!
編輯:澄清,我有一個FXML文件,控制器類和構造函數類。我需要連接到我的控制器類。
https://blogs.oracle.com/jmxetc/entry/connecting_scenebuilder_edited_fxml_to – user2418306