我很难在我的 JavaFX 场景中对齐项目。
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.Pane?>
<Pane minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="app.controller.TableViewController">
<ScrollPane>
<TableView fx:id="tableView" prefHeight="500.0" prefWidth="1100.0" snapToPixel="false" styleClass="100">
</TableView>
</ScrollPane>
<ToolBar maxHeight="35.0" prefHeight="35.0" prefWidth="1200" style="-fx-background-color: #8C0000;">
<ImageView fitHeight="35.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
<Image url="@../images/qmit-search-toolbar-logo.png" />
</ImageView>
<TextArea fx:id="linkInput" maxHeight="30.0" maxWidth="250.0" />
<TextArea fx:id="keywordInput" maxHeight="30.0" maxWidth="100.0" />
<Button fx:id="buttonSearch" maxHeight="30.0" maxWidth="100.0" text="Search QMIT" />
</ToolBar>
</Pane>
我的目标是拥有一个带有 Logo 、两个输入文本字段和一个按钮的工具栏。下面是一个位于屏幕中央的 table 。我到底做错了什么,结果弄得一团糟?
最佳答案
Pane
本身没有布局。
(顺便说一句,请注意 TableView
提供了自己的滚动功能:不要将其包装在滚动 Pane 中。)
例如,使用 BorderPane
:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="app.controller.TableViewController">
<center>
<TableView fx:id="tableView" prefHeight="500.0" prefWidth="1100.0" snapToPixel="false" styleClass="100">
</TableView>
</center>
<top>
<ToolBar maxHeight="35.0" prefHeight="35.0" prefWidth="1200" style="-fx-background-color: #8C0000;">
<ImageView fitHeight="35.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
<Image url="@../images/qmit-search-toolbar-logo.png" />
</ImageView>
<TextArea fx:id="linkInput" maxHeight="30.0" maxWidth="250.0" />
<TextArea fx:id="keywordInput" maxHeight="30.0" maxWidth="100.0" />
<Button fx:id="buttonSearch" maxHeight="30.0" maxWidth="100.0" text="Search QMIT" />
</ToolBar>
</top>
</BorderPane>
Oracle JavaFX 教程有一个 section on layout panes .
关于java - 我的 JavaFX 场景一团糟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44204921/