<?language javascript?>FXMLLoader在尝试处理 fxml 脚本时无法识别该指令(见下文)。错误消息是“未指定页面语言”。我的 fxml 如下(为简洁起见,省略了实际代码):
<?language javascript?>
<!-- differnet includes -->
...
<!-- actual fxml -->
<StackPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="com.xxx.xxx.MainViewController"
prefWidth="1200">
...
<!-- somewhere in the middle of the fxml code -->
<fx:script>
function clearTool1() {
tool1.setValue(null);
}
</fx:script>
...
<StackPane/>
Run Code Online (Sandbox Code Playgroud)
我调查了一下,发现ScriptEngineManagerjavafx 类实际上没有看到任何脚本引擎。特别是,在它的getEngineByName方法中,集合ScriptEngineFactory是空的,所以它没有找到任何JavaScript引擎,并在稍后抛出异常。我不会详细介绍这一点,因为目标不是调试 javafx 源代码,但我认为它作为提示可能很有用。
您是否知道为什么尽管 fxml 和其他所有内容都已正确编写,但脚本语言指令未被识别?
我需要创建一个组合框,它的列表视图末尾可以有一个按钮。此列表可以添加或删除项目,并在项目数超过 5 时显示滚动条。此外,选择项目时此列表视图不会自行关闭。
如何添加“新项目”按钮,如下面的屏幕截图所示?
这是源代码:
helloApplication.java
package com.example.demo;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
stage.setTitle("Hello!");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Run Code Online (Sandbox Code Playgroud)
HelloController.java
package com.example.demo;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.scene.control.skin.ComboBoxListViewSkin;
import java.net.URL;
import java.util.ResourceBundle;
public class HelloController implements Initializable {
@FXML
private …Run Code Online (Sandbox Code Playgroud) 在此应用程序中,HBox mainView 包含一个treeView 和一个包含按钮“A”的overView。按下该按钮将使 overView 消失并显示 ViewA。
主视图.fxml:
<?import javafx.scene.layout.HBox?>
<HBox xmlns:fx="http://javafx.com/fxml/1" fx:id="mainView" fx:controller="com.desktop.controllers.MainController">
<children>
<fx:include source="tree-view.fxml" fx:id="treePane"/>
<fx:include source="overview-view.fxml" fx:id="overviewPane"/>
<fx:include source="A-view.fxml" visible="false" fx:id="APane"/>
</children>
</HBox>
Run Code Online (Sandbox Code Playgroud)
概述-view.fxml:
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<VBox xmlns:fx="http://javafx.com/fxml/1" fx:id="overviewPane" fx:controller="com.desktop.controllers.OverviewController">
<children>
<Button fx:id="AButton" text="A" onAction="#handleSwitchToA"/>
</children>
</VBox>
Run Code Online (Sandbox Code Playgroud)
a-view.fxml:
<?import javafx.scene.control.Label?>
<VBox xmlns:fx="http://javafx.com/fxml/1" fx:id="aPane" fx:controller="com.desktop.controllers.AController">
<children>
<Label fx:id="aLabel" text="A"/>
</children>
</VBox>
Run Code Online (Sandbox Code Playgroud)
由于应用程序非常小,我不想创建多个场景并传递树视图作为参考。相反,我想维护一个场景,只需在概述中切换视图 A ...等之间的可见性。我尝试像本例中那样复制 MainController 的注入
主控制器:
public class MainController implements Initializable {
private Pane rootPane;
@FXML
private HBox mainView;
@FXML …Run Code Online (Sandbox Code Playgroud) 我正在研究一种元素周期表,有一个事件最终,当您将鼠标悬停时,会放大一点所述元素并显示更多信息,但事实是它并没有真正完成这项工作很好。可以说是跟踪,因为如果鼠标移动得有点快,或者很快离开位于边缘的面板,它就不会检测到鼠标的退出。这是鼠标进入或退出时应执行的动画代码:
public void onScale(int i){
double currentScaleX = Panes[i].getScaleX();
double currentScaleY = Panes[i].getScaleY();//stores the current scale
if (currentScaleX == 1.0 && currentScaleY == 1.0) {//verify that said scale is the original (equal to 1)
TranslateTransition translate = new TranslateTransition(Duration.millis(50), Symbol[i]);
translate.setToY(-4);
translate.playFromStart();//move the symbol up a little
TranslateTransition tratn = new TranslateTransition(Duration.millis(50), AtomicNumber[i]);
tratn.setToY(-2);
tratn.playFromStart();
TranslateTransition tratm = new TranslateTransition(Duration.millis(50), AtomicMass[i]);
tratm.setToY(-2);
tratm.playFromStart();
TranslateTransition trnm = new TranslateTransition(Duration.millis(50), Name[i]);
trnm.setToY(3);
trnm.playFromStart();
AtomicMass[i].setVisible(true);
OxidationNumber[i].setVisible(true);//makes the atomic mass and oxidation number visible …Run Code Online (Sandbox Code Playgroud) 我的 fxml 文件上有多个按钮。onAction通过单击任何按钮,将显示定义的 fxml 表单。问题是:
我是否应该使用例如 foreach 加载所有表单,并且当按钮单击正确的表单时仅显示或没有必要?
如果我应该加载所有表单,我应该在initialize函数中执行它吗?
我是新手JavaFx,不知道最好的方法是什么?
编辑:
例如,当 btn1 单击时,将显示“添加用户”表单,当单击“btn2”时,将显示“删除用户”表单,...
问题是:
我是否应该加载添加用户表单并删除用户表单,...当程序启动时以及当例如 btn1 单击添加用户表单时是否显示?
<BorderPane fx:controller="com.project.controller.eventcontroller" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<left>
<VBox prefHeight="400.0" prefWidth="110.0" style="-fx-background-color: #404040;" BorderPane.alignment="CENTER">
<children>
<Button fx:id="btn1" alignment="TOP_LEFT" mnemonicParsing="false" prefHeight="17.0" prefWidth="111.0" text="btn1" />
<Button fx:id="btn2" alignment="TOP_LEFT" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" prefHeight="17.0" prefWidth="111.0" text="btn2">
<VBox.margin>
<Insets top="12.0" />
</VBox.margin>
</Button>
<Button fx:id="btn3" alignment="TOP_LEFT" layoutX="10.0" layoutY="47.0" mnemonicParsing="false" prefHeight="17.0" prefWidth="111.0" text="btn3">
<VBox.margin>
<Insets top="12.0" />
</VBox.margin> …Run Code Online (Sandbox Code Playgroud) 我想知道是否有人知道或知道我可以学习的链接,或者看看如何使用JavaFX 2.0中的fxml文件创建按钮,单选按钮,滚动条等的外观.
我有这个学校的作业,我希望它建立得很好,所以我尝试做一切像公司应用程序,用于按钮和其他元素的皮肤.
我真的很感激任何帮助.
[编辑]大家好,已经有一段时间了,我现在对JavaFX了解得更多,现在当我回头看时,我看到它听起来有多愚蠢,请原谅我的不尊重和糟糕的详细问题.无论如何stackoverflow确保我永远不会再问任何问题.
是否可以自定义TableView的默认滚动条(垂直滚动条)使其更厚?
我需要一个.fxml文件来构建我的GUI.我实际上需要让它在没有鼠标的情况下工作,只需要键盘动作....所以,这里是fxml中的按钮:
<HBox spacing="10" alignment="bottom_right"
GridPane.columnIndex="1" GridPane.rowIndex="4">
<Button text="Login"
onAction="#handleSubmitButtonAction"/>
</HBox>
Run Code Online (Sandbox Code Playgroud)
首先,当按下回车键时,我只需要这个按钮来执行"handleSubmitButtonAction"事件.(如果您对次要目标有任何提示:使用箭头键浏览按钮,而不是一切都消失;))
刚开始使用JavaFx(通常也是Java的初学者),几天来,我一直在尝试使其工作,但一直无法解决。我收到了一个空指针异常,该异常在这里介绍: 什么是NullPointerException,如何解决?
所以我希望这个问题不会因为重复而结束,因为我知道npe是什么,并且(通常)知道如何解决此问题。
我也(大多数时候)知道如何躲避它们和/或修复它们(如果发生),但是在这种情况下,我只是不知道如何解决它。
我还检查了有关fxml的其他问题,但仍然无法解决。
如何从javaFx borderPane中的LeftPane更改CenterPane?
在javaFX的BorderPane中的窗格之间切换在
同一场景中加载新的fxml
在我的应用程序中,我想以borderpane为根,在左侧,我有三个按钮,根据我按的是哪个按钮,按新的fxml和一个tabpane应该在borderpane的中心加载,当我按下按钮时得到一个我认为是由于我没有引用正确的边框的npe,但我看不到我要去哪里错误。
我想做的是当我按下按钮custMenuButton时,fxml应该加载并设置为borderpane的中心。
主班
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Main extends Application {
@FXML
private BorderPane root;
Stage window;
@Override
public void start(Stage primaryStage) throws IOException {
window = primaryStage;
FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindowView.fxml"));
this.root = loader.load();
MainWindowController mwc = new MainWindowController();
mwc.setMain(this);
Scene scene = new Scene(root);
window.setTitle("JavaFX");
window.setScene(scene);
window.show();
}
public static void main(String[] args) {
launch(args);
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试从网格开始创建用户界面。我在scenebuilder中构建了网格,现在我想使用控制器添加列和行。但是,由于网格不会更改大小,因此我的程序似乎未在控制器中运行Initialize()。这是我的主要课程:
import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
//@Override
public void start(Stage primaryStage) {
try {
int width = 7;
int height = 7;
final FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("GUI.fxml"));
loader.setController(new GUIController(width, height));
final Parent root =
FXMLLoader.load(getClass().getResource("GUI.fxml"));
final Scene scene = new Scene(root);
primaryStage.setTitle("GUI");
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器类:
import javafx.fxml.FXML;
import javafx.scene.layout.GridPane;
public class …Run Code Online (Sandbox Code Playgroud)