javafx-8

JavaFX getScene() returns null in initialize method of the controller

 ̄綄美尐妖づ 提交于 2019-12-29 09:02:20
问题 I built a small application in JavaFX yesterday. I wanted to get the Scene of the application in the Controller class. I got an error every time I tried to get the scene in the controller class. I could set the OnKeyPressed-method on a Button in the Controller class, works fine. But it works only fine if the Button is selected.. I can get the scene in the Main-class method replaceSceneContent only. I have read this question already, but I call the getScene()-method in the initialize-method??

Multi-Threading error when binding a StringProperty

折月煮酒 提交于 2019-12-29 08:39:32
问题 I have a question about multi-threading and the binding of a StringProperty. I have a class CacheManager , which contains a Thread which updates my cache with the changes on the server. Now, I want to notify the user with a text and percentage of the progress (which are a Label and ProgressBar in JavaFX). I use public static DoubleProperty and StringProperty for this, which are defined in the CacheManager class. I just bind it like this: progressBar.progressProperty().bind(CacheManager

How to wrap a swing component in a javaFX 2.0 application

徘徊边缘 提交于 2019-12-29 07:34:29
问题 The ability to wrap a swing component in a javaFX application seems to have vanished from javaFX 2: javafx.ext.swing.SwingComponent is not there any more in javaFX 2 beta API. Is there still a way to do this in the new API? 回答1: SwingNode class is used to embed a Swing content into a JavaFX application. Here is the link. 回答2: There is 3rd-party support library, see http://rkennke.wordpress.com/2011/11/16/swing-in-javafx-demo/ 回答3: According to this issue on the FX 2.0 JIRA they aren't

Is there a “fill” function for arbitrary shapes in javafx?

空扰寡人 提交于 2019-12-29 01:28:35
问题 I need to know in which way I can color the following image (PNG) by using JavaFX. This image is currently included in a ImageView of JavaFX: I want to color region 1 blue, the second one red, and the last two purple. How can I do this in JavaFX? Isn't there some kind of function as in Windows Paint? (You know, the painting bucket that fills a certain area with a color between borders). 回答1: Suggested Approach You can use a flood fill algorithm. Sample Code import javafx.application

How can I style a JavaFX menu and its items in CSS?

核能气质少年 提交于 2019-12-28 17:25:11
问题 I've got a MenuBar that is setup as follows in FXML: <MenuBar VBox.vgrow="NEVER"> <menus> <Menu mnemonicParsing="true" text="_File"> <items> <MenuItem mnemonicParsing="true" text="_New Project"/> <MenuItem mnemonicParsing="true" text="_Open…"/> <MenuItem mnemonicParsing="false" text="Quit"/> </items> </Menu> </menus> </MenuBar> This produces a menu as follows: I've successfully styled the MenuBar and the Menu File with the following CSS: .menu-bar { /* The menu bar itself */ } .menu { /* The

Hide input caret of TextField in JavaFX8

陌路散爱 提交于 2019-12-28 06:59:14
问题 I would like to hide the input caret of a TextField in JavaFX8. I already tried to set the text fill to white (my TextField has a white background), but then my user input also disappears. The problem is that the textfield still needs focus, so I also thought of some EventHandler which listens to user input, and focusses on the textfield when a key is pressed, but then I would miss the first key typed. Anyone that knows how to do this? Or is it not possible in JavaFX8? 回答1: Update for Java

JavaFX: Why does stage.setResizable(false) cause additional margins?

ⅰ亾dé卋堺 提交于 2019-12-28 05:21:06
问题 This small JavaFX test application import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class ApplicationWithNonResizableStage extends Application { public static void main(final String[] args) { launch(args); } @Override public void start(final Stage primaryStage) throws Exception { final Rectangle rectangle = new Rectangle(200, 100,

JavaFX - setVisible doesn't “hide” the element

拜拜、爱过 提交于 2019-12-28 05:06:05
问题 In JavaFX, if I have a scene with 2 VBox elements and each VBox has multiple Label in it. If I set the top VBox to invisible , why does the bottom VBox not move up the scene where the top VBox was ? The VBox is invisible but I would expect the other objects to move into its place. I am using FXML to load my controls. 回答1: Node.setVisible(boolean) just toggles the visibility state of a Node . To exclude a Node from its parents layout calculations you additionally have to set its managed state,

How to get GridPane Row and Column IDs on Mouse Entered in each cell of Grid in JavaFX?

╄→尐↘猪︶ㄣ 提交于 2019-12-28 04:28:05
问题 I am trying out JFX Drag and Drop feature in my application (later connecting the objects in a sequence). I could not find any easy way to drag and drop my ImageView/Button at suitable position in my pane, hence I am planning to apply use of GridPane. The GridPane would be a large canvas with more than (50x50) cells. If I specify in my code that I need to drag and drop by ImageView at, let's say, (2,2) cell, I am able to do it. But, I need to give that access to my user. User could move the

Launch JavaFX application from another class

纵然是瞬间 提交于 2019-12-28 01:55:12
问题 I need to start a javafx Application from another "container" class and call functions on the Application, but there doesn't seem to be any way of getting hold of a reference to the Application started using the Application.launch() method. Is this possible? Thanks 回答1: I had the same problem as this and got round it using this hack: import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.BorderPane; import javafx.stage