- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正尝试在 JavaFX 中启动一个项目,但我对自己做错了什么很迷茫。
主要内容
package Software1C482;
/*
* This program is explicitly for the use of Western Governers University's
* Software 1 submission by Andrew Whited.
*/
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import ViewController.HomeWindowController;
/**
*
* @author Andrew Whited
*/
public class InventorySystem extends Application {
private AnchorPane MainScreenView;
private FXMLLoader viewLoader;
public void initMainScreen(Stage window) throws IOException{
viewLoader = new FXMLLoader();
viewLoader.setLocation(InventorySystem.class.getResource("/ViewController/HomeWindow.fxml"));
MainScreenView = viewLoader.load();
Scene scene = new Scene(MainScreenView);
window.setScene(scene);
window.show();
}
public void showMainScreen() throws IOException{
HomeWindowController controller = viewLoader.getController();
controller.setMainApp(this);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Inventory Mangement System");
initMainScreen(primaryStage);
showMainScreen();
}
public static void main(String[] args) {
launch(args);
}
}
相关文件如下。
主窗口 Controller :
package ViewController;
import Model.Inventory;
import static Model.Inventory.getPartInventory;
import static Model.Inventory.getProductInventory;
import static Model.Inventory.removePart;
import static Model.Inventory.removeProduct;
import static Model.Inventory.validatePartDelete;
import Model.Part;
import Model.Product;
import Software1C482.InventorySystem;
import java.io.IOException;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.stage.Modality;
import javafx.stage.Stage;
/**
* FXML Controller class
*
* @author Andrew
*/
//It's the home window.
public class HomeWindowController implements Initializable {
//Declaring the FXML parts.
@FXML
private TableView<Product> TableProduct;
@FXML
private TableColumn<Product, Integer> ProductID, ProductInventoryLevel;
@FXML
private TableColumn<Product, String> ProductName;
@FXML
private TableColumn<Product, Double> ProductPPU;
@FXML
private Button ButtonProductAdd;
@FXML
private Button ButtonProductModify;
@FXML
private Button ButtonProductDelete;
@FXML
private Button ButtonPartSearch;
@FXML
private TableView<Part> TablePart;
@FXML
private TableColumn<Part, Integer> PartID, PartInventoryLevel;
@FXML
private TableColumn<Part, String> PartName;
@FXML
private TableColumn<Part, Double> PartPPU;
@FXML
private TextField SearchFieldPart;
@FXML
private TextField SearchFieldProduct;
private static Part modifyPart;
private static int modifyPartIndex;
private static Product modifyProduct;
private static int modifyProductIndex;
public static int partToModifyIndex() {
return modifyPartIndex;
}
public static int productToModifyIndex() {
return modifyProductIndex;
}
public HomeWindowController() {
}
@FXML
void HomeExitClick(ActionEvent event) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.initModality(Modality.NONE);
alert.setTitle("Confirmation");
alert.setHeaderText("Confirm Exit");
alert.setContentText("Are you sure you want to exit?");
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK) {
System.exit(0);
} else {
System.out.println("Please resume completing form.");
}
}
@FXML
void HomeAddPartsClick(ActionEvent event) throws IOException {
Parent addParts = FXMLLoader.load(getClass().getResource("AddParts.fxml"));
Scene scene = new Scene(addParts);
Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
window.setScene(scene);
window.show();
}
@FXML
void HomeAddProductsClick(ActionEvent event) throws IOException {
Parent addProducts = FXMLLoader.load(getClass().getResource("AddProducts.fxml"));
Scene scene = new Scene(addProducts);
Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
window.setScene(scene);
window.show();
}
@FXML
void HomeModifyPartsClick(ActionEvent event) throws IOException {
modifyPart = TablePart.getSelectionModel().getSelectedItem();
modifyPartIndex = getPartInventory().indexOf(modifyPart);
Parent modifyParts = FXMLLoader.load(getClass().getResource("ModifyParts.fxml"));
Scene scene = new Scene(modifyParts);
Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
window.setScene(scene);
window.show();
}
@FXML
void HomeModifyProductsClick(ActionEvent event) throws IOException {
modifyProduct = TableProduct.getSelectionModel().getSelectedItem();
modifyProductIndex = getProductInventory().indexOf(modifyProduct);
Parent modifyProducts = FXMLLoader.load(getClass().getResource("ModifyProducts.fxml"));
Scene scene = new Scene(modifyProducts);
Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
window.setScene(scene);
window.show();
}
@FXML
void HomeSearchProductsBtn(ActionEvent event) throws IOException {
String searchProd = SearchFieldProduct.getText();
int prodIndex = -1;
if (Inventory.lookupProduct(searchProd) == -1) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Search Error");
alert.setHeaderText("Product not found.");
alert.setContentText("The text entered does not match any Product.");
alert.showAndWait();
} else {
prodIndex = Inventory.lookupProduct(searchProd);
Product tempProd = Inventory.getProductInventory().get(prodIndex);
ObservableList<Product> tempProdList = FXCollections.observableArrayList();
tempProdList.add(tempProd);
TableProduct.setItems(tempProdList);
}
}
@FXML
void HomeDeleteProductsClick(ActionEvent event) throws IOException {
Product product = TableProduct.getSelectionModel().getSelectedItem();
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.initModality(Modality.NONE);
alert.setTitle("Confirm Delete");
alert.setHeaderText("Confirm?");
alert.setContentText("Are you sure you want to delete " + product.getProductName() + "?");
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK) {
removeProduct(product);
updateProductTableView();
System.out.println("Product " + product.getProductName() + " was removed.");
} else {
System.out.println("Product " + product.getProductName() + " was not removed.");
}
}
@FXML
void PartSearchOnAction(ActionEvent event) throws IOException {
String searchPart = SearchFieldPart.getText();
int partIndex = -1;
if (Inventory.lookupPart(searchPart) == -1) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Search Error");
alert.setHeaderText("Part not found.");
alert.setContentText("The text entered does not match any Part.");
alert.showAndWait();
} else {
partIndex = Inventory.lookupPart(searchPart);
Part tempPart = Inventory.getPartInventory().get(partIndex);
ObservableList<Part> tempProdList = FXCollections.observableArrayList();
tempProdList.add(tempPart);
TablePart.setItems(tempProdList);
}
}
@FXML
void HomeDeletePartsClick(ActionEvent event) throws IOException {
Part part = TablePart.getSelectionModel().getSelectedItem();
if (validatePartDelete(part)) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Part Delete Error.");
alert.setHeaderText("Part cannot be removed.");
alert.setContentText("This part is used in a product.");
alert.showAndWait();
} else {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.initModality(Modality.NONE);
alert.setTitle("Product Delete");
alert.setHeaderText("Confirm?");
alert.setContentText("Are you sure you want to delete " + part.getPartName() + "?");
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK) {
removePart(part);
updatePartTableView();
System.out.println("Part " + part.getPartName() + " was removed.");
} else {
System.out.println("Part " + part.getPartName() + " was not removed.");
}
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
PartID.setCellValueFactory(cellData -> cellData.getValue().partIDProperty().asObject());
PartName.setCellValueFactory(cellData -> cellData.getValue().partNameProperty());
PartInventoryLevel.setCellValueFactory(cellData -> cellData.getValue().partInvProperty().asObject());
PartPPU.setCellValueFactory(cellData -> cellData.getValue().partPriceProperty().asObject());
ProductID.setCellValueFactory(cellData -> cellData.getValue().productIDProperty().asObject());
ProductName.setCellValueFactory(cellData -> cellData.getValue().productNameProperty());
ProductInventoryLevel.setCellValueFactory(cellData -> cellData.getValue().productInvProperty().asObject());
ProductPPU.setCellValueFactory(cellData -> cellData.getValue().productPriceProperty().asObject());
updatePartTableView();
updateProductTableView();
}
public void updatePartTableView() {
TablePart.setItems(getPartInventory());
}
public void updateProductTableView() {
TableProduct.setItems(getProductInventory());
}
public void setMainApp(InventorySystem mainApp) {
updatePartTableView();
updateProductTableView();
}
}
最后主页窗口.FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.Scene?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<?import javafx.stage.Stage?>
<Stage xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ViewController.HomeWindowController">
<scene>
<Scene>
<AnchorPane prefHeight="450.0" prefWidth="941.0">
<children>
<Label layoutX="40.0" layoutY="53.0" text="Inventory Management System">
<font>
<Font size="18.0" />
</font>
</Label>
<Label layoutX="497.0" layoutY="108.0" text="Products">
<font>
<Font size="18.0" />
</font>
</Label>
<Rectangle arcHeight="50.0" arcWidth="50.0" fill="#1f93ff00" height="238.0" layoutX="479.0" layoutY="101.0" stroke="BLACK" strokeLineCap="ROUND" strokeLineJoin="ROUND" strokeType="OUTSIDE" width="418.0" />
<TextField fx:id="SearchFieldProduct" layoutX="737.0" layoutY="121.0" onAction="#HomeSearchProductsBtn" />
<Button layoutX="682.0" layoutY="121.0" mnemonicParsing="false" onAction="#HomeSearchProductsBtn" text="Search" />
<TableView fx:id="TableProduct" layoutX="501.0" layoutY="157.0" prefHeight="126.0" prefWidth="374.0">
<columns>
<TableColumn fx:id="ProductID" prefWidth="77.0" text="Product ID" />
<TableColumn fx:id="ProductName" prefWidth="89.0" text="Product Name" />
<TableColumn fx:id="ProductInventoryLevel" prefWidth="94.0" text="Inventory Level" />
<TableColumn fx:id="ProductPPU" prefWidth="113.0" text="Price/Cost Per Unit" />
</columns>
</TableView>
<Button layoutX="624.0" layoutY="290.0" mnemonicParsing="false" onAction="#HomeAddProductsClick" prefHeight="36.0" prefWidth="70.0" text="Add" />
<Button layoutX="708.0" layoutY="290.0" mnemonicParsing="false" onAction="#HomeModifyProductsClick" prefHeight="36.0" prefWidth="70.0" text="Modify" />
<Button layoutX="789.0" layoutY="290.0" mnemonicParsing="false" onAction="#HomeDeleteProductsClick" prefHeight="36.0" prefWidth="70.0" text="Delete" />
<Label layoutX="67.0" layoutY="108.0" text="Parts">
<font>
<Font size="18.0" />
</font>
</Label>
<Rectangle arcHeight="50.0" arcWidth="50.0" fill="#1f93ff00" height="238.0" layoutX="45.0" layoutY="101.0" stroke="BLACK" strokeLineCap="ROUND" strokeLineJoin="ROUND" strokeType="OUTSIDE" width="418.0" />
<TextField fx:id="SearchFieldPart" layoutX="303.0" layoutY="121.0" />
<Button layoutX="248.0" layoutY="121.0" mnemonicParsing="false" onAction="#PartSearchOnAction" text="Search" />
<TableView fx:id="TablePart" layoutX="67.0" layoutY="157.0" prefHeight="126.0" prefWidth="374.0">
<columns>
<TableColumn fx:id="PartID" prefWidth="79.0" text="Part ID" />
<TableColumn fx:id="PartName" prefWidth="86.0" text="Part Name" />
<TableColumn fx:id="PartInventoryLevel" prefWidth="94.0" text="Inventory Level" />
<TableColumn fx:id="PartPPU" prefWidth="114.0" text="Price/Cost Per Unit" />
</columns>
</TableView>
<Button layoutX="190.0" layoutY="290.0" mnemonicParsing="false" onAction="#HomeAddPartsClick" prefHeight="36.0" prefWidth="70.0" text="Add" />
<Button layoutX="274.0" layoutY="290.0" mnemonicParsing="false" onAction="#HomeModifyPartsClick" prefHeight="36.0" prefWidth="70.0" text="Modify" />
<Button layoutX="355.0" layoutY="290.0" mnemonicParsing="false" onAction="#HomeDeletePartsClick" prefHeight="36.0" prefWidth="70.0" text="Delete" />
<Button layoutX="749.0" layoutY="381.0" mnemonicParsing="false" onAction="#HomeExitClick" prefHeight="48.0" prefWidth="149.0" text="Exit" />
</children></AnchorPane>
</Scene>
</scene>
</Stage>
我只能用这三个文件重现错误。报错如下。
ant -f C:\\Users\\Andrew\\Documents\\NetBeansProjects\\Reprex -Dnb.internal.action.name=run run
init:
Deleting: C:\Users\Andrew\Documents\NetBeansProjects\Reprex\build\built-jar.properties
deps-jar:
Updating property file: C:\Users\Andrew\Documents\NetBeansProjects\Reprex\build\built-jar.properties
compile:
run:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.ClassCastException: class javafx.stage.Stage cannot be cast to class javafx.scene.layout.AnchorPane (javafx.stage.Stage and javafx.scene.layout.AnchorPane are in module javafx.graphics of loader 'app')
at InventorySystem/Software1C482.InventorySystem.initMainScreen(InventorySystem.java:32)
at InventorySystem/Software1C482.InventorySystem.start(InventorySystem.java:48)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Exception running application Software1C482.InventorySystem
C:\Users\Andrew\Documents\NetBeansProjects\Reprex\nbproject\build-impl.xml:1330: The following error occurred while executing this line:
C:\Users\Andrew\Documents\NetBeansProjects\Reprex\nbproject\build-impl.xml:902: Java returned: 1
BUILD FAILED (total time: 3 seconds)
如前所述,已重写此问题以更好地解决新问题。我还是个新手,所以这对于 reprex 来说可能很差。
最佳答案
据我所知,您的 fxml 包含 Stage
作为根元素,但您正在将 FXML 中的对象作为 AnchorPane
加载。
InvocationTargetException
的存在意味着在 AnchorPane
上调用了某些构造函数或字段或方法,但对象上不存在该字段/方法。
这是显而易见的,因为 Stage
不是 AnchorPane
的后代,所以即使是多态性也无济于事;当 FXMLLoader 尝试在 AnchorPane
上执行类似 setScene
的操作时,这将失败。
您有两种选择:
我更喜欢第二种,也是比较流行的一种。第一个选项有点多余,因为 javafx 已经在 start
方法中为您提供了一个 Stage
,所以我看不到创建新阶段的好处:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.Scene?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<?import javafx.stage.Stage?>
<AnchorPane prefHeight="450.0" prefWidth="941.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ViewController.HomeWindowController">
<children>
<Label layoutX="40.0" layoutY="53.0" text="Inventory Management System">
<font>
<Font size="18.0" />
</font>
</Label>
<Label layoutX="497.0" layoutY="108.0" text="Products">
<font>
<Font size="18.0" />
</font>
</Label>
<Rectangle arcHeight="50.0" arcWidth="50.0" fill="#1f93ff00" height="238.0" layoutX="479.0" layoutY="101.0" stroke="BLACK" strokeLineCap="ROUND" strokeLineJoin="ROUND" strokeType="OUTSIDE" width="418.0" />
<TextField fx:id="SearchFieldProduct" layoutX="737.0" layoutY="121.0" />
<Button layoutX="682.0" layoutY="121.0" mnemonicParsing="false" text="Search" />
<TableView fx:id="TableProduct" layoutX="501.0" layoutY="157.0" prefHeight="126.0" prefWidth="374.0">
<columns>
<TableColumn fx:id="ProductID" prefWidth="77.0" text="Product ID" />
<TableColumn fx:id="ProductName" prefWidth="89.0" text="Product Name" />
<TableColumn fx:id="ProductInventoryLevel" prefWidth="94.0" text="Inventory Level" />
<TableColumn fx:id="ProductPPU" prefWidth="113.0" text="Price/Cost Per Unit" />
</columns>
</TableView>
<Button layoutX="624.0" layoutY="290.0" mnemonicParsing="false" prefHeight="36.0" prefWidth="70.0" text="Add" />
<Button layoutX="708.0" layoutY="290.0" mnemonicParsing="false" prefHeight="36.0" prefWidth="70.0" text="Modify" />
<Button layoutX="789.0" layoutY="290.0" mnemonicParsing="false" prefHeight="36.0" prefWidth="70.0" text="Delete" />
<Label layoutX="67.0" layoutY="108.0" text="Parts">
<font>
<Font size="18.0" />
</font>
</Label>
<Rectangle arcHeight="50.0" arcWidth="50.0" fill="#1f93ff00" height="238.0" layoutX="45.0" layoutY="101.0" stroke="BLACK" strokeLineCap="ROUND" strokeLineJoin="ROUND" strokeType="OUTSIDE" width="418.0" />
<TextField fx:id="SearchFieldPart" layoutX="303.0" layoutY="121.0" />
<Button layoutX="248.0" layoutY="121.0" mnemonicParsing="false" onAction="#PartSearchOnAction" text="Search" />
<TableView fx:id="TablePart" layoutX="67.0" layoutY="157.0" prefHeight="126.0" prefWidth="374.0">
<columns>
<TableColumn fx:id="PartID" prefWidth="79.0" text="Part ID" />
<TableColumn fx:id="PartName" prefWidth="86.0" text="Part Name" />
<TableColumn fx:id="PartInventoryLevel" prefWidth="94.0" text="Inventory Level" />
<TableColumn fx:id="PartPPU" prefWidth="114.0" text="Price/Cost Per Unit" />
</columns>
</TableView>
<Button layoutX="190.0" layoutY="290.0" mnemonicParsing="false" prefHeight="36.0" prefWidth="70.0" text="Add" />
<Button layoutX="274.0" layoutY="290.0" mnemonicParsing="false" prefHeight="36.0" prefWidth="70.0" text="Modify" />
<Button layoutX="355.0" layoutY="290.0" mnemonicParsing="false" prefHeight="36.0" prefWidth="70.0" text="Delete" />
<Button layoutX="749.0" layoutY="381.0" mnemonicParsing="false" prefHeight="48.0" prefWidth="149.0" text="Exit" />
</children>
</AnchorPane>
我也会将您的代码更改为:
public class InventorySystem extends Application {
private AnchorPane MainScreenView;
private FXMLLoader viewLoader;
public void initMainScreen(Stage window) throws IOException{
viewLoader = new FXMLLoader();
viewLoader.setLocation(InventorySystem.class.getResource("/ViewController/HomeWindow.fxml"));
MainScreenView = viewLoader.load();
Scene scene = new Scene(MainScreenView);
window.setScene(scene);
window.show();
}
public void showMainScreen() throws IOException{
HomeWindowController controller = viewLoader.getController();
controller.setMainApp(this);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Inventory Mangement System");
initMainScreen(primaryStage);
showMainScreen();
}
public static void main(String[] args) {
launch(args);
}
}
关于JavaFX 未启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60482108/
我不知道这是不是问这种问题的最佳地点, 我看到一些 JavaFX伙计们,重新标记 一些问题通过替换 javafx来自 javafx-2并采用新的 javafx-8 .它被弃用了还是什么? 编辑 : 不
错误本身: Error:java: invalid flag: --add-modules=javafx.fxml,javafx.graphics,javafx.controls,javafx.bas
这个想法是让一个应用程序在每个显示器上显示两个不同的窗口(阶段),该应用程序应该知道计算机有多少个显示器及其分辨率。 javafx有可能吗? 最佳答案 对于当前版本的 JavaFX (2.2),您可以
我正在将我的项目从 javafx 1.3 转换为 javafx 2.1。但我对 javafx.lang 有疑问包裹。 最佳答案 JavaFX 1.3 lang 包内容被拆分并移至下一个位置: 时长变为
当我尝试将标签添加到 gridpane 中时,如第二张图片所示,它不起作用。我已经尝试了很多东西,比如添加 CSS,但它仍然无法正常工作。为什么第 113 和 114 行不起作用? (opcje.se
我有一个JavaFX ContextMenu分配给滚动面板的鼠标右键单击。它会打开,但在滚动 Pane 外部单击时不会关闭。我可以在滚动 Pane 中添加另一个鼠标事件以将其隐藏,但这只能解决1个问题
我有一个tableview,其中附有一个可观察到的自定义类对象的列表(类类型:SalesInvoiceNetSale)。该表中的所有数据都可以正常显示。可观察列表中的最后一项是总计行(类类型:Sale
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 2年前关闭。 Improve this questi
我想知道如何在JavaFX中绘制半圆。我尝试使用Shape和QuadCurve,但无法制作出完美的半圆。 这是我要绘制的图片: 最佳答案 您链接的图片实际上是一个半圆环。您可以通过绘制嵌套的2条圆弧和
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我正在寻找 JavaFX 支持的图像类型(最新)列表,例如PNG、JPEG、TIFF。不同的搜索引擎没有帮助......知道从哪里开始吗? 更特别的是,我对 16 位灰度图像(不同格式)和罕见的受支持
我希望在 javafx 中让标签每 0.1 秒闪烁一次。文本显示在后台运行的 ImageView gif 的顶部。我将如何去做,或者您对最佳方法有什么建议? 谢谢 最佳答案 @fabian 的解决方案
我需要测试所选项目的值以调用不同的方法,因此我编写了添加侦听器的代码,但是该代码生成语法错误 @FXML private JFXComboBox cmbComp; cmbComp.valuePrope
我正在 Javafx 中编写一个非常简单的应用程序,其中舞台上有一个带有文本框的按钮作为一个场景。现在,我想要的行为是,当我单击按钮时,我可以使用另一个按钮加载另一个场景和舞台上的一个文本框,然后删除
编辑:如果用户单击“删除”以删除 ListView 中的项目,我会弹出一个警告框。它有效,但我希望它能超越原来的舞台。它出现在我的第一台显示器上。有什么方法可以设置警报显示时的位置吗? 请注意,“所有
我想使用 JavaFX 编写一个笔画绘图应用程序。我有一个压敏绘图板,如果能够读取笔的压力和倾斜值,那就太好了。 JavaFX 有一个 API 可以处理鼠标、触摸和滑动输入,但似乎没有任何东西可以产生
我在 JavaFX 中使用条形图和折线图。当我使两个图表大小相同并将它们放在同一位置时,它们完美地相互重叠。我如何使折线图显示在条形图的顶部。 目前我已将它们的不透明度设置为 0.7,这样它们“看起来
此问题与 this 相关。现在我想为字段值等于某个值的行着色。 @FXML private TableView tv_mm_view; @FXML private Ta
我有一个程序,可以生成高度图(0-255 的整数的 2D 数组),并使用 Shape3D“Box”对象为每个“像素”构建 3D View ,其高度与其在高度图中的值成比例。这会创建一个看起来很酷的四四
我想为 JavaFX 创建上下文菜单。这是我测试过的代码。但是由于某种原因,当我右键单击树节点时没有上下文菜单。你能帮我找出我的错误吗。 import java.util.Arrays; import
我是一名优秀的程序员,十分优秀!