javafx-8

Get value from Date picker

与世无争的帅哥 提交于 2019-11-29 14:08:06
问题 I want to get the value from JavaFX datepicker and store the value as Date Object: final DatePicker datePicker = new DatePicker(LocalDate.now()); Date date = datePicker.getValue(); grid.add(datePicker, 1, 9); Can you tell me how I can convert LocalDate to Date ? 回答1: As the name implies, LocalDate does not store a timezone nor the time of day. Therefore to convert to an absolute time you must specify the timezone and time of day. There is a simple method to do both, atStartOfDay(ZoneId). Here

Multi-Threading error when binding a StringProperty

怎甘沉沦 提交于 2019-11-29 14:02:59
I have a question about multi-threading and the binding of a StringProperty. I have a class CacheManager , which contains a Thread which updates my cache with the changes on the server. Now, I want to notify the user with a text and percentage of the progress (which are a Label and ProgressBar in JavaFX). I use public static DoubleProperty and StringProperty for this, which are defined in the CacheManager class. I just bind it like this: progressBar.progressProperty().bind(CacheManager.progress); someLabel.textProperty().bind(CacheManager.status); Now, in the Updater thread, I update these

JavaFX - getScene() returns null

柔情痞子 提交于 2019-11-29 13:29:27
I just started using JavaFX Scene Builder to build a small application. It is made up of a controller class 'Login.java' which belongs to 'login.fxml', in which the FXML file 'registrierung.fxml' is loaded via a method called 'registrationClicked(ActionEvent event)': public class Login { @FXML private void registrationClicked(ActionEvent event){ try{ ((Node) (event.getSource())).getScene().getWindow().hide(); FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/fxml/registrierung.fxml")); Parent root = (Parent) loader.load(); Stage stage = new Stage(); Scene scene = new Scene(root)

Can't import custom components with custom cell factories

♀尐吖头ヾ 提交于 2019-11-29 13:04:43
In JavaFX 2.2 I've been having trouble importing custom components that have a custom cell factory defined in the FXML. Lets say my custom component is the following public class CustomComponent extends VBox{ public CustomComponent() { try { FXMLLoader loader = new FXMLLoader(getClass().getResource("CustomComponent.fxml")); loader.setRoot(this); loader.setController(this); loader.load(); } catch (IOException e ){ throw new RuntimeException(e); } } } And the corresponding FXML is <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.*?> <?import java.lang.*?> <?import javafx

JavaFX key interruptions?

Deadly 提交于 2019-11-29 12:59:58
I'm trying to write a game in JavaFX but I'm having a slight issue with it and that's the key listeners getting interrupted by other key presses. I'm using scene.setOnKeyPressed(KeyEvent) and it works. When the player holds down a key they move continuously but if they hit another key it forgets about the first key even if they let go of the second key. I'm trying to figure out how to allow them to do one action and then when the key they were holding is released if they're still holding the other one go back to that. James_D This is similar to this question , though the requirements look

Static @FXML variables in FXML Controller

吃可爱长大的小学妹 提交于 2019-11-29 12:55:45
I upgraded from javafx 8 b109 to b116 and my FXML controller class has the injected variables as null when it initializes. I tried it with the sample netbeans fxml app. @FXML private static Label label; @Override public void initialize(URL url, ResourceBundle rb) { label.setText("static test"); } The problem is with the static keyword, remove that and it works. It was working fine in b109 with static variables. When writing my app initially, I figured static made sense. They're created when the application loads and there's only ever one copy of the scene. Is there a way around this without

javafx 2 webview custom url handler, don't work relative url

喜欢而已 提交于 2019-11-29 12:53:20
I have simple app with code: webView.getEngine().load("classpath:data/index.html"); Custom URLStreamHandler: public class Handler extends URLStreamHandler { private final ClassLoader classLoader; public Handler() { this.classLoader = getClass().getClassLoader(); } public Handler(ClassLoader classLoader) { this.classLoader = classLoader; } @Override protected URLConnection openConnection(URL u) throws IOException { URL resourceUrl = classLoader.getResource(u.getPath()); if(resourceUrl == null) throw new IOException("Resource not found: " + u); return resourceUrl.openConnection(); } } installed

Tooltip on Live LineChart

时光总嘲笑我的痴心妄想 提交于 2019-11-29 12:53:05
I found many examples how to add Tooltip on a LineChart but no information or example how to add Tooltip on Live LineChart. import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; import java.util.logging.Level; import java.util.logging.Logger; import javafx.animation.AnimationTimer; import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.scene.Node; import javafx.scene.Scene; import javafx

Drag and Drop from ListView to TreeView

那年仲夏 提交于 2019-11-29 12:41:53
I just want to drag and drop an item from my ListView to a specific position in my TreeView . I know how to handle DragEvent s. But how can I get the dropped position of my treeView? With "position" I mean "on which treeview-item dropped (get reference from this treeview-item)". package main; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.Event; import javafx.event.EventHandler; import javafx.event.EventType; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.*; import

Changing the text of a label from a different class in JavaFX

心不动则不痛 提交于 2019-11-29 12:37:59
This question was already asked here but was not able to find any answers. I have reproduced a similar situation where I would like to change the text of a label from another class using the controller FXMLDocumentController.java public class FXMLDocumentController implements Initializable { @FXML private Label label; @FXML private void handleButtonAction(ActionEvent event) { System.out.println("FXMLDocumentController.#handleButtonAction"); label.setText("Hello World!"); Connector.Connecting(); } @Override public void initialize(URL url, ResourceBundle rb) { // TODO } public void setLabelText