fxml

how do I get an element in JavaFx using an id?

孤者浪人 提交于 2019-12-05 06:00:56
I am new to FXML and I am trying to create a handler for all of the button clicks using a switch . However, in order to do so, I need to get the elements using and id. I have tried the following but for some reason (maybe because I am doing it in the controller class and not on the main) I get a stack overflow exception. public class ViewController { public Button exitBtn; public ViewController() throws IOException { Parent root = FXMLLoader.load(getClass().getResource("mainWindow.fxml")); Scene scene = new Scene(root); exitBtn = (Button) scene.lookup("#exitBtn"); } } So how will I get an

Should we use FXML in JavaFX custom controls or not?

跟風遠走 提交于 2019-12-05 03:45:18
It seems wired to ask this, I would think that using FXML to write our custom components is the obviously the right way to go. But as we can see from ControlsFX, JFXextras and even the book 'Mastering JavaFX8 controls do not use or mention the use of FXML in custom controls. Despite that, the official documentation to say to go on that route, and create JavaFX controls via FXML. What is the more correct way and why ? There are two kinds of custom controls in JavaFX: fx:root based custom controls : These custom controls are styleable (support CSS), but are not skinnable. If you're an

fxml combobox, get the selected value into javafx

有些话、适合烂在心里 提交于 2019-12-05 00:15:43
how can i catch the selected value of a fxml combobox and implement it into a javafx class? i gave the combobox the fx:id "sample" and created a button with onAction="#test" and tried .getValue and .getPromptText. @FXML private ComboBox<String> Sample; @FXML protected void test( ActionEvent event ) { String output = (String) Sample.getValue(); System.out.println(output); String output = (String) Sample.getPromptText(); System.out.println(output); } If i try to run it i get an error: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at javafx.fxml.FXMLLoader

JavaFX 8 DatePicker features

笑着哭i 提交于 2019-12-04 22:51:09
问题 I just start using the new JavaFX 8 control DatePicker . In DatePicker User Experience Documentation, it is stated that it has couple of cool features that I would like to have in my GUI application: I want to change the format from mm/dd/yyyy to dd/mm/yyyy . I would like to restrict the date that can be selected. The user can only select from today until the same day of next year. Display Hijri dates besides the original ones: How to implement these features? The JavaDoc doesn't say much

Refill a SVG Path with onMouseEntered event in JavaFX

寵の児 提交于 2019-12-04 22:41:19
i'm working on a personal project which includes a .fxml document(created from a .svg file with NetBeans). Here is the Map as you can see.Moreover, all the regions are converted into a SVG Path in .fxml file. The thing is i can handle with mouse events with using JavaFX Scene Builder with a controller class however, i want to refill (or in other words repaint or highlight ) the region whenever mouse is entered on it. Here is main class public class JavaFXApplication1 extends Application { @Override public void start(Stage primaryStage) throws IOException { Parent root = FXMLLoader.load

Scala - Get FXML UI-Elements

家住魔仙堡 提交于 2019-12-04 19:25:35
I´m working on a Scala/JavaFX project with IntelliJ and a plugin for scala. The typical way in Java to access elements of your fxml-file is to set an id for each element you want to access and then in your controllerclass declare a variable like "@FXML private Label mylabelid;". In Scala it works almost the same way as you can see in my source code. BUT i get a NullPointerException in line 73 (marked with a PROBLEM-comment). This is the only label, which is just set to null. I tried diffrent things. Every single element is getting set as expected apart from missingInputLabel. LoginView.fxml: <

JavaFX custom controller factory

帅比萌擦擦* 提交于 2019-12-04 18:53:00
问题 I have been experimenting with the FXMLLoader and using the setControllerFactory method using a custom Callback<P,R> implementation. The ORACLE documentation says the following: An implementation might return a null value to indicate that it does not or cannot create a controller of the given type; in this case, the default controller construction mechanism will be employed by the loader. The result I want to achieve is that I can use a dependency injection framework to create any controllers

JavaFX style class won't refresh

你。 提交于 2019-12-04 18:51:07
问题 I'm adding a style class to an node if it's selected and then remove it if I select other item. Even if I remove the style class the style wont refresh so it wont go back to normal state: admin_category_label.getStyleClass().remove(admin_category_label.getStyleClass().indexOf("selected")); admin_category_label.getStyleClass().add("clear"); but the style will stay the same as class selected 回答1: This is a bug. It is reported here Removal of hovered style class, does not update styling. You may

What is the “mnemonicParsing” attribute in Java FX

旧巷老猫 提交于 2019-12-04 17:43:10
问题 I have been working with SceneBuilder and I observe that it applies the attribute of mnemonicParsing and equates it to false for every Node that I make. What exactly is it? What difference does it make in Layout.xml ? 回答1: This refers to the Labeled.mnemonicParsing property. It registers a keyboard shortcut to activate the element (using the letter following _ in the text + Alt (Windows, don't know if it's the same key on other OS too)). E.g. Button btn = new Button(); btn.setText("_Say

Java FXML load (Dynamic) from absolute path

一世执手 提交于 2019-12-04 17:00:58
I want to load fxml files from an absolute path or a path outside of my jar system. background: it will be a simple plugin-system that look's in the plugin folder for all fxml files (later jar files) and include it automatically in a TabPane. String fxmlpath = "C:\\plugin\\pluginfxml.fxml"; try { Parent root = FXMLLoader.load(getClass().getResource(fxmlpath)); //Load root in Tabpane and so on ... } It should be simple: Parent root = FXMLLoader.load(Paths.get(fxmlpath).toUri().toURL()); FXMLLoader takes in a URL as its argument, so we just use the NIO Paths class to get the Path, then convert