Tag: javafx 8

在gui线程中触发异步事件

TL; DR我正在寻找让一个线程在另一个线程中引发事件的方法 编辑:我说“立即”这个词,正如一些评论者指出的那样,是不可能的。 我的意思是它应该合理地快速发生,如果gui线程处于空闲状态(如果我的工作正确,应该是),在毫秒到纳秒的范围内。 案例:我有一个有Parent类的项目。 该Parent类创建一个子线程’Gui’,它包含一个javafx应用程序并实现Runnable。 Parent和Gui都引用了相同的BlockingQueue。 我想要发生的事情:我希望能够将对象从父类发送到Gui线程,并让Gui接收某种事件,立即调用某种处理函数,所以我知道得到一个或者队列中的更多对象并将它们添加到gui中。 用于“观察者模式”的其他解决方案通常涉及位于while循环中的观察者,检查一些同步队列以寻找新数据。 这对我的应用程序不起作用,因为Javafx要求只能从gui线程修改gui元素,并且gui线程必须在很大程度上保持空闲状态,以便它有时间重绘事物并响应用户事件。 循环会导致应用程序挂起。 我发现似乎有潜力的一个想法是从父线程中断Gui线程,并触发某种事件,但我找不到任何方法来实现这一点。 有任何想法吗? 针对这种情况的最佳做法是什么?

如何解决事件onEditCommit上的类型不匹配错误?

我在Fxml中使用了onEditCommit事件来在用户编辑后检索数据。 FXML代码 – : 实现onEditCommit事件 – : public void editCommit_0(CellEditEvent event) { System.out.println(“Value edited: On edit new value is “+event.getNewValue()); } 错误 – : Exception in thread “JavaFX Application Thread” java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) at […]

Java fxml app无法正常工作 – 无法找到符号错误

我从https://github.com/HassanAlthaf/AlarmApplication下载了一个java fxml应用程序,当我尝试运行它时,从MainView.java类中获取“找不到符号”错误。 以下是Mainview.java文件中的代码 import java.net.URL; import java.util.ResourceBundle; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.control.TextField; public class MainView implements Initializable { @FXML private TextField hoursField; @FXML private TextField minutesField; @FXML private TextField secondsField; private final AlarmController alarmController; @FXML private void startAlarm(ActionEvent event) { int response = this.alarmController.startAlarm( this.hoursField.getText(), this.minutesField.getText(), this.secondsField.getText() ); […]

JavaFX:如何动态反序列化创建区域图系列?

我使用区域图中的列表动态添加系列。 我想打开这个系列。 我需要这个,因为我想在db中保存Area Chart系列数据。 当app执行时,它是这样的: 用户可以通过填写文本字段并单击“添加”按钮来添加系列: 我想要的是当用户点击“保存”按钮时,它应该将已添加的系列转换为数据,这样我就可以将其存储在数据库中。 但是我尝试过它并没有给我准确的数据。 根据聊天系列我想得到这样的输出: Series 0 Employees: 5 Series 0 Start: 1 Series 0 End: 7 Series 1 Employees: 3 Series 1 Start: 9 Series 1 End: 12 但是我得到了这个: Series 0 Employees: 5 Series 0 Start: 1 Series 0 End: 5 Series 1 Employees: 3 Series 1 Start: 10 Series […]

如何在JavaFX ScatterChart中从点到X轴绘制一条线?

现在我正在使用JavaFX ScatterChart,我需要从数据点到X轴绘制一条线,如下图所示。 谢谢你的帮助!

JavaFX和SwingNode – 部分黑色窗口

我尝试使用SwingNode在JavaFX中使用Swing组件: public class MyTest extends Application { @Override public void start(Stage stage) { final SwingNode swingNode = new SwingNode(); FlowPane pane = new FlowPane(); Button btn = new Button(“1”); btn.setVisible(false); pane.getChildren().add(btn); createAndSetSwingContent(swingNode); pane.getChildren().add(swingNode); stage.setScene(new Scene(pane, 100, 50)); stage.show(); btn.setVisible(true); } private void createAndSetSwingContent(final SwingNode swingNode) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { swingNode.setContent(new […]

是否有更简单(更轻松)的方法将文本置于JavaFX 8的“区域”中?

所以,首先,我已经实现了我想要的,也就是说,在“区域”的中心显示一些文本。 屏幕截图(右上角): 现在,我遇到的问题是我是如何实现这一点的…这是整个标签的FXML摘录: 正如您所看到的,为了实现直观上应该简单的东西(在区域的中心显示一些文本),我必须创建一个BorderPane并在其放置一个Label ; 我甚至不必指定标签上的文字应该居中…… 我尝试过的其他事情是: 放置Label本身:那么ScrollPane的分隔符将被彻底忽略; 左侧将扩展到Scene的整个宽度(是吗?)减去分隔符的宽度加上标签的文本,更重要的是,文本将位于区域的顶部; 用AnchorPane包围它:虽然这确实保持了区域的大小,但文本将出现在左上角而不是中心。 有比上述更简单的解决方案吗?

JavaFx:如果我想在initialize()之后做一些事情,在场景秀之前,我该如何实现呢?

我想做一些事情,在控制器的initialize()方法完成之后,但在场景show之前。在场景显示之前是否会调用任何方法?我想在方法中加入一些代码。 FXMLLoader loader = new FXMLLoader(); loader.setLocation(getClass().getResource(“sample.fxml”)); AnchorPane pane = loader.load(); Scene gameScene = new Scene(pane); //I load a secne above,the I will get the controller,set some properties,then,use the properties to read a file before the secene show. GameUIController controller = loader.getController(); controller.setGameFileLoacation(“game1.txt”);//I set a property here.I want to use it to read game file,and […]

JavaFX应用程序无法使用本机exe包启动

我已经构建了一个可以通过其jar文件执行的JavaFX应用程序。 但是,如果我尝试使用本机exe包运行它,我收到两个弹出窗口: com / npap / dicomrouter / Main – 没有主类 无法启动JVM 并且应用程序无法启动。 这是我的Main类(大部分内容): package com.npap.dicomrouter; public class Main extends Application { … public static void main(String[] args) throws IOException { try { JUnique.acquireLock(appId); alreadyRunning = false; log.info(“application is going to start running!!!!”); } catch (AlreadyLockedException e) { alreadyRunning = true; log.info(“application is already running!!!!”); […]

如何将数字传递给TextField JavaFX?

我正在研究简单的计算器,用户在TextField输入两个数字,结果显示在结果TextField 。 我使用Double.parseDouble从输入TextFields获取文本并对其应用操作。 但我无法将其传递给第三个输入字段。 我试图将double结果强制转换为String,但它没有用。 如何简单地将数字传递给TextField? double num1 = Double.parseDouble(numberInput1.getText()); double num2 = Double.parseDouble(numberInput2.getText()); double resultV = (num1 + num2); resultInput.setText(resultV); 最后一行不起作用,因为格式不同。