Java JFX在边框窗格中时没有滚动条
我正在尝试在边框窗格中布局表。当我这样做时,缩小窗口会截断表格,并且不会显示滚动条 这是布局图:Java JFX在边框窗格中时没有滚动条,java,javafx,javafx-8,Java,Javafx,Javafx 8,我正在尝试在边框窗格中布局表。当我这样做时,缩小窗口会截断表格,并且不会显示滚动条 这是布局图: <BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://java
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication1.SimpleUIController">
<center>
<AnchorPane>
<TableView fx:id="table" prefHeight="500.0" prefWidth="1000.0" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="50.0" AnchorPane.topAnchor="10.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn fx:id="colName" prefWidth="500.0" text="Name" />
<TableColumn fx:id="colPrice" prefWidth="400.0" text="Price" />
</columns>
</TableView>
</AnchorPane>
</center>
</BorderPane>
如果我这样删除边框窗格:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication1.SimpleUIController">
<TableView fx:id="table" prefHeight="500.0" prefWidth="1000.0" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="50.0" AnchorPane.topAnchor="10.0">
<columns>
<TableColumn fx:id="colName" prefWidth="500.0" text="Name" />
<TableColumn fx:id="colPrice" prefWidth="400.0" text="Price" />
</columns>
</TableView>
</AnchorPane>
使用borderpane时如何获取滚动条?请尝试将滚动窗格设置为父节点,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<HBox
maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308"
xmlns="http://javafx.com/javafx/8.0.111"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox
maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308"
HBox.hgrow="ALWAYS">
<children>
<ScrollPane
fitToHeight="true"
fitToWidth="true"
maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308"
VBox.vgrow="ALWAYS">
<content>
<BorderPane
maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308"
minHeight="-Infinity"
minWidth="-Infinity">
<center>
<TableView
maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308">
<columns>
<TableColumn
maxWidth="1.7976931348623157E308"
prefWidth="400.0"
text="C1" />
<TableColumn
maxWidth="1.7976931348623157E308"
prefWidth="500.0"
text="C2" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</center>
</BorderPane>
</content>
</ScrollPane>
</children>
</VBox>
</children>
</HBox>
这看起来很接近我需要的,但是,如果我放大窗口,桌子将无法使用可用空间。我只是桌子周围有很多空位。我可以避免吗?@zorro2b尝试更新的代码吗?这是一个小消息,有这么多层的包装,但希望将工作。