简体   繁体   English

JavaFX8 tabpane的选项卡没有切换

[英]JavaFX8 tabpane's tab not switching

Below is my code for GridPane with TabPane. 下面是我使用TabPane的GridPane代码。

There are 2 tabs inside a TabPane. TabPane中有2个选项卡。

When I click preview on SceneBuilder the tabs are not switching upon clicking on the tab head. 当我在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>

It is expected that it doesn't do anything on mouse click as you set it transparent for mouse events: mouseTransparent="true" 当您为鼠标事件设置透明时,预计它不会对鼠标单击执行任何操作: mouseTransparent="true"

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

I guess it was done by accident, but when you set mouseTransparent property to true: 我猜它是偶然完成的,但是当你将mouseTransparent属性设置为true时:

If true, this node (together with all its children) is completely transparent to mouse events. 如果为true,则此节点(及其所有子节点)对鼠标事件完全透明。 When choosing target for mouse event, nodes with mouseTransparent set to true and their subtrees won't be taken into account. 选择鼠标事件的目标时,将mouseTransparent设置为true的节点及其子树将不予考虑。

Remove the mentioned part from your FXML and your preview will work like a charm. 从FXML中删除提到的部分,您的预览将像魅力一样工作。

In SceneBuilder, on the Properties Tab of TabPane: 在SceneBuilder中,在TabPane的Properties选项卡上:

在此输入图像描述

<?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>

Change here tabpane according to your required size. 根据您所需的尺寸更改此处tabpane。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM