fxml

label.setText NullPointerException

拥有回忆 提交于 2019-11-29 07:41:42
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. However if I call the locationLabel() method in my Player class I get a NullPointerException when

JavaFX class controller scene reference

风流意气都作罢 提交于 2019-11-29 06:39:13
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. Sergey Grinev 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 fine to ask Node about his parent or scene. If you still want to handle that separately there are

How to switch scenes in JavaFX

Deadly 提交于 2019-11-29 04:08:29
I have looked on many pages to try and find out how to switch scenes but I have been unsuccessful. I have a calculator and my goal is to select a menu option to change Calculators(ie: basic and scientific). Right now I am just testing so here is my code relevant to this question thus far (I am using Scene Builder): @FXML private MenuItem basic; @FXML private MenuItem testSwitch; public static void main(String[] args) { Application.launch( args ); } @Override public void start(Stage primaryStage) throws Exception { Parent pane = FXMLLoader.load( getClass().getResource( "calculator.fxml" ) );

Login Application with 1 stage and multiple scene in JavaFX

橙三吉。 提交于 2019-11-29 02:25:52
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 some help ;) Hopefully you understand what I want to achieve. Worth mentioning, i=I'm dealing with

How to make canvas Resizable in javaFX?

有些话、适合烂在心里 提交于 2019-11-29 02:00:03
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 isResizable() { return true; } } is extends from Canvas is the only solution to make canvas Resizable ? because

Getting started on Scala + JavaFX desktop application development

北城余情 提交于 2019-11-29 00:58:16
问题 Is there some guide or walkthrough to building a Scala + JavaFX desktop application? I'm having hard time finding a good source and I am using IntelliJ IDEA as the IDE. Even the most simplistic desktop hello world samples would help a lot, because I have little clue where to start. Update: This is what I have now: import javafx.application.Application import javafx.scene.Scene import javafx.scene.layout.StackPane import javafx.stage.Stage import javafx.scene.control.Label class Test extends

sort tableview with drag and drop (rows)

主宰稳场 提交于 2019-11-28 23:53:29
my aim is to sort a tableview with drag and drop. I followed this example: http://docs.oracle.com/javafx/2/fxml_get_started/fxml_tutorial_intermediate.htm For drag and drop I added the fxml via Scene Builder <TableView fx:id="tableView" onDragDetected="#dragDetected" onDragDropped="#dragDropped" onDragOver="#dragOver" and made the controllers @FXML private void dragDetected(MouseEvent event) { System.out.println("dragDetected"); Integer idx; idx = tableView.getSelectionModel().getFocusedIndex(); Dragboard db = tableView.startDragAndDrop(TransferMode.MOVE); ClipboardContent content = new

Label and Text differences in JavaFX

好久不见. 提交于 2019-11-28 23:33:32
问题 What is the difference between javafx.scene.text.Text and javafx.scene.control.Label? The documentation says: Label is a non-editable text control. The Text class defines a node that displays a text. But the Label class has a method "setText" and "textProperty", therefore is editable. 回答1: As Harry Blargle pointed out, "non-editable" means "not editable by the user." So both Label and Text are non-editable. Label and Text have different CSS properties. Label inherits from Labeled, Control,

close fxml window by code, javafx

走远了吗. 提交于 2019-11-28 17:46:19
I need to close the current fxml window by code in the controller I know stage.close() or stage.hide() do this in fx how to implement this in fxml? I tried private void on_btnClose_clicked(ActionEvent actionEvent) { Parent root = FXMLLoader.load(getClass().getResource("currentWindow.fxml")); Scene scene = new Scene(root); Stage stage = new Stage(); stage.setScene(scene); stage.show(); } but it doesn't work! All help will be greatly appreciated. Thanks! give your close button an fx:id, if you haven't yet: <Button fx:id="closeButton" onAction="#closeButtonAction"> In your controller class: @FXML

To Hide JavaFx fxml or JavaFx swing application to System Tray

◇◆丶佛笑我妖孽 提交于 2019-11-28 16:53:29
问题 I want to develop a client app for website . I want the app to reside in system tray when minimised. I dont know how to accomplish this task . Is their any example for this type of operation. 回答1: The key here is to set the implicit exit to false Platform.setImplicitExit(false); Also is important to show and hide the stage in a new thread. Platform.runLater(new Runnable() { @Override public void run() { stage.show(); } }); Platform.runLater(new Runnable() { @Override public void run() { stage