gpt4 book ai didi

JavaFX tabpane 选项卡不切换

转载 作者:行者123 更新时间:2023-11-29 04:44:57 26 4
gpt4 key购买 nike

下面是我的带有 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>

最佳答案

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

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

我想这是偶然完成的,但是当你设置 mouseTransparent 时属性为真:

If true, this node (together with all its children) is completely transparent to mouse events. When choosing target for mouse event, nodes with mouseTransparent set to true and their subtrees won't be taken into account.

从您的 FXML 中删除提到的部分,您的预览将非常有效。

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

enter image description here

关于JavaFX tabpane 选项卡不切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37561160/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com