javafx-2

JavaFx:What if I want to do something after initialize(),before the scene show,how can I achieve this?

让人想犯罪 __ 提交于 2019-12-30 11:55:07
问题 I want to do something ,after the controller's initialize() method done,but before the scene show.Is there any method will be invoked before the scene show?I want to put some code into the method. 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.

JavaFX 2: Save edit in TableCell

心已入冬 提交于 2019-12-30 11:11:49
问题 In my JavaFX-program I use a TableCell where you can edit a value. Like shown at the examples on the JavaFX-page "Example", I use this function to save the changes (function is set on TextField in edit Cell) textField.setOnKeyReleased(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent t) { if (combo.match(t)) { commitEdit(textField.getText()); } else if (t.getCode() == KeyCode.ESCAPE) { cancelEdit(); } } When using ENTER to leave the cell, the value is changed / saved, but

Wait for Platform.RunLater in a unit test

眉间皱痕 提交于 2019-12-30 10:13:08
问题 I have a presentation class storing an XYChart.Series object and updating it by observing the model. The Series updating is done by using Platform.runLater(...) I want to unit-test this, making sure the commands in runLater are performed correctly. How do I tell the unit-test to wait for the runLater commands to be done? Right now all I do is Thread.Sleep(...) on the test-thread to give the FXApplicationThread the time to complete, but that sounds stupid. 回答1: The way I solved it is as

Multiple controller for one FXML file

夙愿已清 提交于 2019-12-30 10:00:19
问题 I have one fxml file controlled by one controller. I want to separate the controller into multiple parts as if placed in one controller makes a long code. Unfortunately, fx:controller can only be placed in the root. Are there any suggestions for me how to separate the controller? 回答1: I recommend to create custom controls - use several smaller FXML files rather than one big FXML file. Here is the tutorial: http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm 回答2: During the

Multiple controller for one FXML file

我只是一个虾纸丫 提交于 2019-12-30 10:00:07
问题 I have one fxml file controlled by one controller. I want to separate the controller into multiple parts as if placed in one controller makes a long code. Unfortunately, fx:controller can only be placed in the root. Are there any suggestions for me how to separate the controller? 回答1: I recommend to create custom controls - use several smaller FXML files rather than one big FXML file. Here is the tutorial: http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm 回答2: During the

javafx change css at runtime

若如初见. 提交于 2019-12-30 08:19:52
问题 Is it possible to change css for a JavaFX application while it is running? The effect I am looking for is changing skins or themes at the click of a button. The UI is in an FXML file if that makes any difference. I have tried Scene.getStylesheets() .add(getClass().getResource(skinFileName).toExternalForm()); which has no effect. thanks 回答1: It should have the effect. Try this full demo code: public class CssThemeDemo extends Application { private String theme1Url = getClass().getResource(

Placing an image into a JavaFX 2 table

六眼飞鱼酱① 提交于 2019-12-30 07:10:05
问题 I'm trying to do something pretty simple. I want to place an icon in a column for a particular row in a table. If it's a folder, display a folder icon. If it's a file, display a file icon. Does anyone know how to do this in JavaFX 2? I've tried so many things and this seems like it should be pretty simple or at least an example somewhere. 回答1: Okay so I had a huge dummy moment. Turns out that I had my image url path wrong. I did find a site that provides a great example for adding elements

JavaFX & FXML: how do I set the default selected item in a ChoiceBox in FXML?

試著忘記壹切 提交于 2019-12-30 06:03:09
问题 I have the following FXML: <ChoiceBox> <items> <FXCollections fx:factory="observableArrayList"> <String fx:value="2 minutes" /> <String fx:value="5 minutes" /> <String fx:value="15 minutes" /> </FXCollections> </items> </ChoiceBox> But in the GUI it just shows a ChoiceBox with a default of nothing. I would like the first element in the list to be the default, and for a choice of "null" or nothing to be prohibited. How do I accomplish this? 回答1: I added the value attribute to the ChoiceBox tag

How to populate TableView dynamically with FXML and JavaFX

柔情痞子 提交于 2019-12-30 05:27:07
问题 How do I define my table in FXML and then use my JavaFX code to populate it dynamically at runtime? 回答1: Define the TableView in the fxml file. Few things to note: the root should have a controller class associated with it. the TableView and TableColumn should have fx:id attributes specified. <BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="com.example.MyController"> <center> <ScrollPane disable="false" visible="true"> <content> <TableView fx:id="myTableView" prefHeight="-1.0"

Starting a second JavaFX Application

落花浮王杯 提交于 2019-12-30 05:08:40
问题 I'm trying to launch a JavaFx application from within a JavaFx application, but it looks like Application.launch() can only be called once. Does this mean I have to start a separate JVM... as in exec("java... or is there another way? More background info. I want my JavaFx app to be able to build and run JavaFx apps. Right now it compiles classes in-memory, loads the classes... it would be really unfortunate to have to resort to writing everything to the filesystem so I can get a jar on the