fxml

Unable to get Scene from MenuItem in JavaFX

北战南征 提交于 2019-11-28 03:15:51
问题 I am trying to change the scene in a javafx stage based on menuItem click. Here is my sample.fxml: <?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import java.net.*?> <?import javafx.geometry.Insets?> <?import javafx.scene.control.*?> <?import javafx.scene.control.Button?> <?import javafx.scene.control.Label?> <?import javafx.scene.image.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.layout.GridPane?> <AnchorPane prefHeight="-1.0" prefWidth="560.0" styleClass=

Can't load FXML in another package (JavaFX)

烈酒焚心 提交于 2019-11-28 02:28:10
For some reason I'm getting an error when I try to load an FXML which is in a different package: MainApp.java " FXMLLoader loader = new FXMLLoader(); System.out.println("view folder: " + MainApp.class.getResource("view/RootLayout.fxml")); // returns null loader.setLocation(MainApp.class.getResource("view/RootLayout.fxml")); Folder structure: Error message: Exception in Application start method java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke

label.setText NullPointerException

[亡魂溺海] 提交于 2019-11-28 01:33:17
问题 Hi first time here but here goes: I have a JavaFX application that changes the FXML UI labels dynamically and the data is pulled from a Player class. The two classes in question are Player.java and InterfaceHandler.java . The player class stores player details and I want to pass the details to the Interface class which sets the text on the labels. As a test my FXML UI just has a button and two labels. If it click the button it calls the handleButton method it sets locationLabel to "Town" fine

Java FX fxml on Action

旧时模样 提交于 2019-11-28 00:42:45
I want to add a method to a button which is defined in my Controller class in the console is only an error which tells me that it couldn't find the method here is the code sample.fxml <?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml" fx:controller="sample.Controller"> <children> <Button layoutX="126" layoutY="90" text="lololol" onAction="#test" fx:id="button" /> </children>

Java vs JavaFX Script vs FXML. Which is better way of programming in JavaFX?

旧巷老猫 提交于 2019-11-28 00:14:06
I am new to JavaFX and I come across 2-3 ways of designing UI in JavaFX. Simple Java file which is same methodology we used in Swing JavaFX Script which I don't know FXML which is xml based file for UI designing Which of these is better? and why? Just to put some light, javafx script was used prior to javafx 2.0 and is no longer in use ! You can use this approach, if you are more familiar with the coding UI in java. But, I personally dislike the approach, since it makes the code complex when you have a way too complex application. JavaFX Script was in use prior to JavaFX 2.0 and is no longer

JavaFX class controller scene reference

♀尐吖头ヾ 提交于 2019-11-28 00:13:32
问题 Is there any way of getting the Scene object of an FXML loaded file from the associated class controller. I'm doing something like this: @FXML private AnchorPane anchor; Scene scene = anchor.getScene(); but i'd like a solution that does not reference the AnchorPane control. 回答1: Why not? Controller is an abstract class, he's not aware about UI unless you deliberately make him know. Nodes (inlcuding AnchorPane) are another story, they hardly exists outside for scenegraph. So it's perfectly

How to add a CSS stylesheet in FXML

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 22:59:44
I'd like to link a css file to my application. In my fxml file I use this: <stylesheets> <URL value="@../stylesheet1.css" /> </stylesheets> ...and I can see a styled preview when I open the fxml file in scenebuilder. But when I try to run the application I get an error: java.net.MalformedURLException: no protocol: ../stylesheet1.css So I tested it this way: <stylesheets> <String fx:value="stylesheet1.css" /> </stylesheets> and now it's other way round - the application starts and applies the css, but I don't see the preview in scenebuilder. The error message: "The file stylesheet1.css doesn't

JavaFX multiple FXML and 1 shared controller

与世无争的帅哥 提交于 2019-11-27 19:11:20
问题 I have created a root FXML which is a BorderPane and it has his own root controller. I want to dynamicly add FXML's to the center of this borderpane. Each of these fxml's share the same controller, root controller. I have done this in netbeans by choosing an exsisting controller when creating an empty FXML file. I also have gave the nodes different id names, but the root controller does not recognize the nodes in these fxml's. Is it possible to share the same controller for different fxml's?

Bootstrap with JavaFX

江枫思渺然 提交于 2019-11-27 18:50:41
I am creating a GUI in a java fxml project using netbeans. I wanted to use bootstrap to style the gui but I have noticed that everything in javafx is prefixed with fx- . Is there still a way to get bootstrap to work anyway for my project? Does bootstrap even work with javafx? Rendering Bootstrap inside a JavaFX WebView Bootstrap is an HTML based framework. So to use Bootstrap in JavaFX, use JavaFX's HTML rendering component WebView to render Bootstrap HTML/CSS and JavaScript. Sample Application Sample application performing a basic integration of Bootstrap and a JavaFX UI. The JavaFX buttons

How to connect FX controller with main app

五迷三道 提交于 2019-11-27 17:18:45
I have a main app class and a fxmlController class but I am entangled in connecting/organizing(confused how these are called and how I should organize them to make the GUI connected business logic) business logic and GUI. Can someone please tell the order in which following function are called or can anyone help how I should call them? Main class: public void Main() //constructor public static void main() // our main public void start() //I don't know what it is, what purpose it has // and where should be called //Note: In main function there is a call as following fxmlController class: public