2014-01-20 64 views

回答

21

設置你的網格的項目在其

  1. 創建GridPane。
  2. 將節點放置在網格中。
  3. 在網格中選擇一個節點。

在這個階段選擇網格中的節點是非常非常重要的。 。 。

後,要麼:

A.使用菜單項

  1. 選擇Modify | GridPane
  2. 選擇任何

    Increase Row Span 
    Decrease Row Span 
    Increase Column Span 
    Decrease Column Span 
    

B.使用佈局面板

  1. 修改行範圍或列範圍值。

佈局注

要真正得到的東西,以填補在你想要的方式電網和跨行或列,您可能需要修改節點的其他佈局參數,或者它電網約束佈局面板。例如,按鈕通常不會超出其首選大小,因此請將其最大高度和寬度設置爲MAX_VALUE。另一個例子是在兩列中間放置一個標籤,將它的標籤設置爲始終,並將其Halignment設置爲CENTER。

樣品截圖

有設置的行和列寬菜單項,也有對相同的佈局文本字段在最右邊。不幸的是,StackOverflow會壓縮圖片並使其變得模糊。

gridview

樣品FXML

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

<?import java.lang.*?> 
<?import java.util.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.scene.layout.*?> 
<?import javafx.scene.paint.*?> 

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2"> 
    <children> 
    <GridPane layoutX="116.0" layoutY="155.0"> 
     <children> 
     <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Button" GridPane.columnIndex="0" GridPane.columnSpan="2147483647" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" GridPane.vgrow="ALWAYS" /> 
     <Label text="Label" GridPane.columnIndex="0" GridPane.rowIndex="0" /> 
     <Label maxWidth="-1.0" text="Label" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.rowIndex="0" /> 
     <Label text="Label" GridPane.columnIndex="0" GridPane.rowIndex="2" /> 
     <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" GridPane.rowSpan="2" /> 
     <Label text="Label" GridPane.columnIndex="2" GridPane.rowIndex="2" /> 
     <Label text="Label" GridPane.columnIndex="2" GridPane.rowIndex="3" /> 
     </children> 
     <columnConstraints> 
     <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> 
     <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> 
     <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> 
     </columnConstraints> 
     <rowConstraints> 
     <RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> 
     <RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> 
     <RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> 
     <RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> 
     </rowConstraints> 
    </GridPane> 
    </children> 
</AnchorPane> 
+0

清潔和漂亮的移出,謝謝 – ozhan

相關問題