javafx-2

Update progress bar and multiple labels from thread

不问归期 提交于 2019-12-21 21:29:33
问题 I'm working on a JavaFX application that let's the user select a folder and then parse it's contents to find MP3 files and read their metadata. I got this working with Swing although I found it hard to make the user interface look good. Thus I'm trying to do the same in JavaFX. In the original Swing app, I create a thread which starts the parsing of files in the folder the user selected. It works like this: Find out total number of files to parse - The number of files and the number of

new line in TextBox (JavaFX 2.0)

你离开我真会死。 提交于 2019-12-21 21:23:19
问题 I'm trying to create TextBox with JavaFX 2.0 . My source is following: TextBox textBox = new TextBox(); textBox.setPrefSize(150, 600); textBox.setText("Hello\n world!"); Result is: How could I create new line in TextBox ? 回答1: Creating a multilined TextBox is a JavaFX 1.3 feature. In JavaFX 2.0 you have to use a TextArea. TextArea textArea = new TextArea(); textArea.setPrefRowCount(2); textArea.setText("Hello\nworld!"); The JavaFX UI Controls tutorial does not mention the TextArea control.

Pass object from one scene to another

谁都会走 提交于 2019-12-21 20:48:36
问题 As I'm learning the new world of JavaFX2 I stumbled on another annoying problem. I'm developing a program with multiple scenes (~10 scenes). For that I created a small class like this: public class SceneSelector { ... public void setScene(Stage stage, String fxmlfilename, ObservableList ol) throws Exception{ String s = "../" + fxmlfilename; Parent root = FXMLLoader.load(getClass().getResource(s)); root.setUserData(ol); Scene scene = new Scene(root); stage.setScene(scene); //show the stage

How can JavaFX controllers access other services?

旧巷老猫 提交于 2019-12-21 20:17:23
问题 I am using JavaFX 2 with Scala. I have the class Application extends javafx.application.Application which does things like reads app configuration, etc. Then it fires up the main window. This main window needs to be connected to a controller called MainWindow . I can do it with fx:controller="com.foo.bar.MainWindow" , however, in this case the instance of MainWindow is unable to access my application's configuration, etc. One thing that came to my mind is to instantiate the MainWindow

Is drag and drop supported by TreeItem?

这一生的挚爱 提交于 2019-12-21 12:00:13
问题 I'm currently working with a JavaFx-2's TreeView representing a file system. I want to enable drag and drop to allow move operations, but it looks like TreeItem doesn't include drag events listeners. I was only able to implement drag and drop on the englobing TreeView object, but it doesn't work for sub-items. Am I missing something, or are drag and drop events not supported for TreeItems yet? 回答1: Question answered by Csh on the Oracle Forums : https://forums.oracle.com/forums/message.jspa

generating a MouseEvent in JavaFX

霸气de小男生 提交于 2019-12-21 11:02:44
问题 I'm in need of simulating a MouseEvent.MOUSE_CLICKED . I want to use the fireEvent method of a particular Node in order to dispatch an event of the aforementioned type. However, I am struggling with generating one. It appears that javafx.scene.input.MouseEvent has no valid constructor, but old java.awt.event.MouseEvent objects can be instantiated this way. Still, I haven't found any working solution for conversion. How do I go around this? Thanks. 回答1: You can generate a MouseEvent using the

Prevent an accordion in JavaFX from collapsing

痴心易碎 提交于 2019-12-21 09:22:06
问题 Is there an easy way of preventing an accordion in JavaFX 2.1 from fully collapsing? I have an accordion with a few entries but if the user clicks the active accordion entry it collapses the accordion. I could probably use a mouse click listener to check do the check and act accordingly but this feels like it should be even simpler than that to accomplish. 回答1: Add a listener to the currently expanded accordion pane and prevent it from being collapsed by the user by modifying it's collapsible

JavaFX 2 buttons size fill width and are each same width?

亡梦爱人 提交于 2019-12-21 07:54:51
问题 Working in Java FX 2.2. The Scene has a horizontal width that is fixed but is unknown at compile time. I want to place 2 or more buttons in a horizontal row that completely fills the horizontal space in the Scene AND that are each exactly the same width. The number of buttons changes dynamically with the program state. What program snippet will accomplish this? 回答1: This code from the HBox javadoc will almost do what you want, except that "buttons themselves are different sizes based on the

JavaFX 2 buttons size fill width and are each same width?

非 Y 不嫁゛ 提交于 2019-12-21 07:52:35
问题 Working in Java FX 2.2. The Scene has a horizontal width that is fixed but is unknown at compile time. I want to place 2 or more buttons in a horizontal row that completely fills the horizontal space in the Scene AND that are each exactly the same width. The number of buttons changes dynamically with the program state. What program snippet will accomplish this? 回答1: This code from the HBox javadoc will almost do what you want, except that "buttons themselves are different sizes based on the

JavaFX 2: resizable rectangle containing text

筅森魡賤 提交于 2019-12-21 06:57:12
问题 I want to display a rectangle that contains a text/label. For this purpose I created a stackpane and added a rectangle and a label to it. However the text/label is not centered correctly. It is placed outside of the rectangle (to the left). This is the code I am currently using: createRectangle(String name) { pane = new StackPane(); text = new Label(name); rect = new Rectangle(); // bind rectangle width to text width and add 10 rect.widthProperty().bind(text.widthProperty().add(10)); rect