javafx-2

JavaFX Class controller Stage/Window reference

折月煮酒 提交于 2019-12-29 06:29:14
问题 Is there any way of getting the Stage/Window object of an FXML loaded file from the associated class controller? Particularly, I have a controller for a modal window and I need the Stage to close it. 回答1: I could not find an elegant solution to the problem. But I found these two alternatives: Getting the window reference from a Node in the Scene @FXML private Button closeButton ; public void handleCloseButton() { Scene scene = closeButton.getScene(); if (scene != null) { Window window = scene

Interoperability between Graphics2D and GraphicsContext

你说的曾经没有我的故事 提交于 2019-12-29 04:45:15
问题 I am working with a group which is looking to target a graphics renderer in Java. At the moment I am trying to figure out whether targeting java.awt.Graphics2D will be forward compatible. Namely, can other libraries like JavaFX display renders from a Graphics2D instance? Is there interoperability between java.awt.Graphics2D and javafx.scene.canvas.GraphicsContext ? Or, if not between Graphics2D and GraphicsContext directly, is there any means of displaying a Graphics2D render in a JavaFX

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

How to make an undecorated window movable / draggable in JavaFX?

北城余情 提交于 2019-12-28 12:34:07
问题 I have to create an application in which minimize and maximize button will be disabled. I have used "StageStyle.UNDECORATED" with which the application will not be movable or draggable anymore, so I am searching for any other alternative to make my application. Do anyone having solution for this? 回答1: To achieve the window to be undecorated but still movable/dragable you have to handle the appropriate MouseEvent on any node of your choice. Example: import javafx.application.Application;

How to make an undecorated window movable / draggable in JavaFX?

老子叫甜甜 提交于 2019-12-28 12:33:08
问题 I have to create an application in which minimize and maximize button will be disabled. I have used "StageStyle.UNDECORATED" with which the application will not be movable or draggable anymore, so I am searching for any other alternative to make my application. Do anyone having solution for this? 回答1: To achieve the window to be undecorated but still movable/dragable you have to handle the appropriate MouseEvent on any node of your choice. Example: import javafx.application.Application;

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,

JavaFX ProgressBar: how to change bar color?

北慕城南 提交于 2019-12-28 04:23:08
问题 I'm trying to change the color of bar in ProgressBar with pBar.setStyle("-fx-accent: green"); but I have encountered a problem: that doesn't seem to work right for me! (Or I just don't understand something) here is the code: public class JavaFXApplication36 extends Application { @Override public void start(Stage primaryStage) { AnchorPane root = new AnchorPane(); ProgressBar pbRed = new ProgressBar(0.4); ProgressBar pbGreen = new ProgressBar(0.6); pbRed.setLayoutY(10); pbGreen.setLayoutY(30);

Javafx 2 click and double click

自闭症网瘾萝莉.ら 提交于 2019-12-28 02:43:26
问题 I would like to know if it was possible to detect the double-click in JavaFX 2 ? and how ? I would like to make different event between a click and a double click. Thanks 回答1: Yes you can detect single, double even multiple clicks: myNode.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { if(mouseEvent.getButton().equals(MouseButton.PRIMARY)){ if(mouseEvent.getClickCount() == 2){ System.out.println("Double clicked"); } } } }); MouseButton

How to create custom components in JavaFX 2.0 using FXML?

好久不见. 提交于 2019-12-28 02:25:08
问题 I can't seem to find any material on the subject. To give a more concrete example, let's say I want to create a simple component that combines a checkbox and a label. Then, populate a ListView with instances of this custom component. UPDATE: see my answer for complete code UPDATE 2: For an up-to-date tutorial, please, consult the official documentation. There was a lot of new stuff that was added in 2.2. Finally, the Introduction to FXML covers pretty much everything you need to know about

View html from archive using WebView

南楼画角 提交于 2019-12-25 18:41:53
问题 I have zip-compressed file, which contains a set of html pages. I need to load html-pages from it. I need to redefine the mechanism of resolve of links. It is possible using WebView javafx? 回答1: If I understand well your question. I'm guessing that you need to open html files. I extracted the next code from javafx 2 tutorial from Oracle WebView browser = new WebView(); WebEngine webEngine = browser.getEngine(); webEngine.load("http://mySite.com"); The load function takes a regular URL, so you