JavaFX8 tabpane的选项卡没有切换

时间:2016-06-01 06:37:09

标签: java javafx javafx-8

下面是我使用TabPane的GridPane代码。

TabPane中有2个标签。

当我在SceneBuilder上单击预览时,单击标签页时不会切换选项卡。

<?xml version="1.0" encoding="UTF-8"?>
    <?import javafx.scene.control.SplitPane?>
    <?import javafx.scene.control.Tab?>
    <?import javafx.scene.control.TabPane?>
    <?import javafx.scene.control.TreeView?>
    <?import javafx.scene.layout.AnchorPane?>
    <?import javafx.scene.layout.ColumnConstraints?>
    <?import javafx.scene.layout.GridPane?>
    <?import javafx.scene.layout.RowConstraints?>
    <GridPane id="content" alignment="CENTER" prefHeight="310.0" prefWidth="800.0" styleClass="mainParent" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.gvj.sndp.view.controller.HomeController">
      <children>
          <SplitPane dividerPositions="0.18421052631578946" prefHeight="160.0" prefWidth="200.0" GridPane.rowIndex="2">
            <items>
                <TreeView fx:id="menuTreeView" prefHeight="273.0" prefWidth="115.0" />
                <TabPane fx:id="tabPane" mouseTransparent="true" prefHeight="200.0" prefWidth="200.0" rotateGraphic="true">
                   <tabs>
                      <Tab text="Untitled Tab">
                        <content>
                          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                        </content>
                      </Tab>
                      <Tab text="Untitled Tab">
                        <content>
                          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                        </content>
                      </Tab>
                   </tabs></TabPane>
            </items>
          </SplitPane>
      </children>
      <columnConstraints>
        <ColumnConstraints hgrow="ALWAYS" minWidth="-1.0" prefWidth="-1.0" />
      </columnConstraints>
      <rowConstraints>
          <RowConstraints maxHeight="35.0" minHeight="22.0" prefHeight="30.0" valignment="CENTER" vgrow="ALWAYS" />
        <RowConstraints maxHeight="35.0" minHeight="22.0" prefHeight="22.0" valignment="CENTER" vgrow="ALWAYS" />
          <RowConstraints valignment="CENTER" vgrow="ALWAYS" />
      </rowConstraints>
    </GridPane>

2 个答案:

答案 0 :(得分:2)

当您为鼠标事件设置透明时,预计它不会对鼠标单击执行任何操作:mouseTransparent="true"

<TabPane fx:id="tabPane" mouseTransparent="true" prefHeight="200.0" prefWidth="200.0" rotateGraphic="true">

我猜这是偶然的,但是当你将mouseTransparent属性设置为true时:

  

如果为true,则此节点(及其所有子节点)完全是   对鼠标事件透明。选择鼠标事件的目标时,   将mouseTransparent设置为true且其子树不会的节点   考虑到了。

从FXML中删除提到的部分,您的预览将像魅力一样。

在SceneBuilder中,在TabPane的“属性”选项卡上:

enter image description here

答案 1 :(得分:1)

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

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TreeView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>


<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <TabPane nodeOrientation="LEFT_TO_RIGHT" tabClosingPolicy="UNAVAILABLE">
        <tabs>
          <Tab text="Tab1" />
          <Tab text="Tab2">
            <content>
              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="229.0" prefWidth="600.0" />
            </content>
          </Tab>
        </tabs>
      </TabPane>
   </children>
</Pane>

根据您所需的尺寸更改此处tabpane。