我只是在试用JavaFX并且正在强行进入它,因为它被认为是未来.我正在尝试创建一个包含4列的表.列和表应调整大小以填充父窗格.我不能为我的生活让这个工作.我现在已经尝试了4个多小时,并且tableview没有调整大小.
这是我的FXML文件.
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import java.net.*?>
<?import javafx.geometry.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.collections.*?>
<?import t.cubed.fxml.*?>
<BorderPane styleClass="root" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="t.cubed.fxml.FXMLDocumentController">
<top>
<MenuBar fx:id="menuBar" styleClass="menu-bar">
<menus>
<Menu text="File">
<items>
<MenuItem onAction="#handleOpenAction" text="Open" />
<MenuItem onAction="#handleExitAction" text="Exit" />
</items>
</Menu>
<Menu text="Edit">
<items>
<MenuItem onAction="#handleWeightAction" text="Edit Weights" />
<MenuItem onAction="#handleFilterAction" text="Edit Filters" />
<MenuItem onAction="#handleOptionsAction" text="Options" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<center>
<GridPane> …Run Code Online (Sandbox Code Playgroud) 我在将边框窗格中的按钮根据舞台居中时遇到问题。它根据边框窗格居中,但我希望它位于窗口的正中心。
我指的是图片的底部,其中有播放按钮和难度选择框。
我使用边框将难度部分放在右侧,将播放按钮放在中间。
正如您所看到的,游戏并不在图片的中心。
我想这样做,但我不知道该怎么做。我认为我可以将左节点的宽度设置为等于右节点的宽度,但我的左节点没有任何内容。
// bottom section for positioning
BorderPane settings = new BorderPane();
settings.setPadding(new Insets(10));
// play button
Button playBtn = new Button("Play");
settings.setCenter(playBtn);
// difficulty options
Label diffLabel = new Label("Difficulty: ");
ChoiceBox<String> diffBox = new ChoiceBox<String>(FXCollections.observableArrayList(
"Easy", "Standard", "Hard"
));
diffBox.getSelectionModel().select(1);
// for wrapping the diffuclty.
HBox difficulty = new HBox(diffLabel, diffBox);
difficulty.setAlignment(Pos.CENTER);
difficulty.setSpacing(10);
settings.setRight(difficulty);
Run Code Online (Sandbox Code Playgroud) 我BorderPane用作FXML文件的根窗格.但是,编译器抱怨BorderPane没有controller属性!如何将控制器类绑定到FXML其根目录BorderPane?
<BorderPane id="rootPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.saei.explorer.FXMLDocumentController">
Run Code Online (Sandbox Code Playgroud)
我正在使用,BorderPane因为它能够在重新调整窗口大小时拉伸布局.
我有一个BorderPane. Scene& 我在该窗格中有一个背景图像。我对该图像的代码:
BorderPane B_pane = new BorderPane();
Image image = new Image("/Client/social3.png",width,height,false,true,true);
ImageView imageView = new ImageView(image);
B_pane.getChildren().add(imageView);
Run Code Online (Sandbox Code Playgroud)
后来我在该窗格中添加了一些VBox作为 Left 、 Right 部分。我想通过特定的单击更改其背景图像BorderPane(显然不会导致 VBox 的位置、元素发生任何变化)。Button我该怎么做?