fxml

How to access a JavaFx Stage from a Controller?

戏子无情 提交于 2019-12-18 05:56:32
问题 I'm converting a pure JavaFx app, in which the code below worked fine when put all in one class, to a FXML one, where the Stage declaration and the button handler are in separate classes. In the a Controller, I'm trying to implement a method that will allow the user to choose a directory and store it in a variable for later use: private File sourceFile; DirectoryChooser sourceDirectoryChooser; @FXML private void handleSourceBrowse() { sourceDirectoryChooser.setTitle("Choose the source folder"

FXML Load exception

早过忘川 提交于 2019-12-18 05:49:07
问题 I got a problem that I absolutely can't solve on my own because I have just started using JAVA FX. I get a nasty javafx.fxml.LoadException: , but I have done exactly like a guide, but I cant get my Main to run. This is the the exception output: apr 07, 2014 4:06:37 EM application.Main start ALLVARLIG: null javafx.fxml.LoadException: /C:/Users/Jakob/Dropbox/java_kurser/Project%20Timeline/bin/application/LoginGUI.fxml at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source) at javafx

Login Application with 1 stage and multiple scene in JavaFX

和自甴很熟 提交于 2019-12-18 03:43:53
问题 I am doing a timeline project. I have successfully created a login system and menus for everything, but when I press the buttons I have done so it will open a new window(with stage, scenes). I have read that it isn't the best approach. The best way would be to only have 1 primary stage, and that one would be when I launch the application, the login. But I have looked for information about multiple scenes with one stage but I have not found any good solutions. Would really really appreciate

JavaFX8 list bindings similar to xaml

試著忘記壹切 提交于 2019-12-17 21:30:07
问题 I am unable to bind in fxml a collection to a customized template. Here the code how I would do it in xaml: <ListView ItemsSource="{Binding PersonCollection}"> <StackPanel Orientation="Horizontal"> <Label Content="{Binding FirstName}"></Label> <ListView ItemsSource="{Binding MiddleNames}"> <Label Content="{Binding}"></Label> </ListView> <Label Content="{Binding LastName}"></Label> </StackPanel> </ListView> Here the Model: class Person { String FirstName, LastName; String[] MiddleNames; } And

JavaFX 2.0 + FXML - strange lookup behaviour

最后都变了- 提交于 2019-12-17 20:36:31
问题 I want to find a VBox node in a scene loaded with FXMLoader thanks to Node#lookup() but I get the following exception : java.lang.ClassCastException: com.sun.javafx.scene.control.skin.SplitPaneSkin$Content cannot be cast to javafx.scene.layout.VBox The code : public class Main extends Application { public static void main(String[] args) { Application.launch(Main.class, (java.lang.String[]) null); } @Override public void start(Stage stage) throws Exception { AnchorPane page = (AnchorPane)

JavaFX How to set max/min window size?

两盒软妹~` 提交于 2019-12-17 19:39:49
问题 Does setMinSize() work on containers, GridPane for example? I have found that in my programm GridPane ignores min. size properties while resized manually. Here is the FXML code: <GridPane fx:id="gp" prefHeight="134.0" prefWidth="238.0" xmlns:fx="http://javafx.com/fxml" fx:controller="javafxapplication12.SampleController"> <columnConstraints> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <

How to make canvas Resizable in javaFX?

删除回忆录丶 提交于 2019-12-17 18:56:15
问题 In javaFX to resize a canvas there is no such method to do that, the only solution is to extends from Canvas. class ResizableCanvas extends Canvas { public ResizableCanvas() { // Redraw canvas when size changes. widthProperty().addListener(evt -> draw()); heightProperty().addListener(evt -> draw()); } private void draw() { double width = getWidth(); double height = getHeight(); GraphicsContext gc = getGraphicsContext2D(); gc.clearRect(0, 0, width, height); } @Override public boolean

JavaFx scene lookup returning null

末鹿安然 提交于 2019-12-17 17:11:00
问题 Button btn = new Button("ohot"); btn.setId("testId"); itemSection.getChildren().add(btn); Node nds = itemSection.lookup("‪#‎testId‬"); What is wrong with above code?? I am getting nds=null it should be btn 回答1: Lookups in conjunction with applyCSS Lookups are based on CSS. So CSS needs to be applied to the scene for you to be able to lookup items in the scene. See the applyCSS documentation for more information. To get accurate results from your lookup, you might also want to invoke layout,

How to add a CSS stylesheet in FXML

不打扰是莪最后的温柔 提交于 2019-12-17 16:27:59
问题 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

Binding a Label's text property (in an FXML file) to an IntegerProperty (in a controller)

亡梦爱人 提交于 2019-12-17 12:36:25
问题 I've set up a data binding between a Label in an FXML file and an IntegerProperty in the associated controller. The problem is that, while the label gets set to the correct value upon initialization, it is not updating when the property's value changes. FXML file <?xml version="1.0" encoding="UTF-8"?> <?import java.net.*?> <?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.text.*?> <GridPane xmlns:fx="http://javafx.com/fxml"