如何调整javafx标签长度的大小

时间:2014-09-29 11:23:11

标签: java javafx-2 fxml

我创建了一个简单的javafx页面。我有一个tabPane,它有标签。我在gridPane中包装tabPane,当我的页面调整大小时,它也会调整大小。它工作正确并且tabPane调整大小但它的选项卡没有调整大小(选项卡的大小,而不是选项卡内容的大小)。我怎么能这样做?

TabPane.java:

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

public class TabPane extends Application {
public static void main(String[] args){
    launch(args);
}

@Override
public void start(Stage stage) throws Exception {
    GridPane ap = (GridPane) FXMLLoader.load(getClass().getResource("gridTest.fxml"));
    Scene scene = new Scene(ap);
    stage.setScene(scene);
    stage.show();
   }
}

gridTest.fxml:

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

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

<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="50.0" minWidth="50.0" prefHeight="588.0" prefWidth="600.0" stylesheets="@../GridTest.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
  <columnConstraints>
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
  </columnConstraints>
  <rowConstraints>
    <RowConstraints maxHeight="190.0" minHeight="10.0" percentHeight="10.0" prefHeight="11.0" vgrow="SOMETIMES" />
    <RowConstraints maxHeight="381.0" minHeight="10.0" percentHeight="10.0" prefHeight="381.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" percentHeight="84.4" prefHeight="30.0" vgrow="SOMETIMES" />
  </rowConstraints>
<children><VBox prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: red;" /><TabPane prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" GridPane.rowIndex="1">
  <tabs>
    <Tab styleClass="tb" text="Untitled Tab 1">
      <content>
        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
      </content>
    </Tab>
    <Tab styleClass="tb" text="Untitled Tab 2">
      <content>
        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
      </content>
    </Tab>
  </tabs>
</TabPane><StackPane prefHeight="150.0" prefWidth="200.0" style="-fx-background-color: blue;" GridPane.rowIndex="2" />
</children>
</GridPane>

0 个答案:

没有答案