John Damien Smith

Ranch Hand
+ Follow
since Jan 26, 2012
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by John Damien Smith

You want to configure a column resize policy for the table.

1 week ago
There is an additional example of highlighting cells in a table based upon a boolean cell value over on StackOverflow:
Note, that is for a specific cell, but from your question, you want to highlight entire rows, in which case the following StackOverflow question might be more appropriate:
The trick from there, which I just copy here, is to use a row factory:
1 week ago
That link you provided to a solution isn't very helpful, it just ends up at an empty bing page when I click on it.
1 week ago
> That is why I am keen to have a progress bar. As it stands, all of the above steps are in one Task object. To the user, it would look like the application has locked up whilst the steps are being completed.

I don't understand why it would be the case that the application would appear to have locked up.
I also don't see why it is necessary to define multiple tasks for this process (you can of course), I just don't know why it would be necessary.
If you want an example of a Task with progress indication, see:
If you try it, you will find that the progress of the task is displayed and the application is still interactive (it has not locked up).
If you are still having issues, provide an mcve.
1 month ago
IMO, you really shouldn't be trying to solve the problem you have in the way that you are trying to solve it.

Applets are deprecated technology, it says so in the documentation of the class you are trying to use:

If the legacy application is important, then rewrite it not to use applets and any code or technology related to them.
1 month ago
There are some really poor suggestions on this thread.

Don't run a busy loop with a counter that goes to a million on the JavaFX thread, it will hang your app periodically.
Similarly, don't call Thread.sleep on the JavaFX application thread, it will also hang your app periodically.

For most operations in JavaFX, you need to relinquish control of the JavaFX application thread, so that the system can take action on the commands which you have issued.  Not doing so just hangs the UI and application and, in addition, it doesn't do what you expect.  It doesn't do the first thing, then pause, then do the next thing.  Instead, the system just buffers up all the things you asked it to do, and only executes them all at once after you release control back to the system.


Knute's suggestion to use a Task which runs a separate thread which does the pauses, then a runLater call to execute the event at each period, does at least fix one of the main problems occurring here by shifting the pause into its own thread rather than in the JavaFX application thread.


If you want a delay for a period in JavaFX, where something happens after a period, one way to accomplish that is to use a PauseTransition with a setOnFinished call:

An advantage of this over a task-based approach which spawns another thread is that there is no other user thread involved, so you have less concurrent code to manage and worry about, which is pretty much always a good thing.


For more complex interactions, a Timeline can be used rather than a PauseTransition.

The key thing about timeline and pause transition is that they are event-based, so you provide a callback event handler function in each case whenever the event you wish (the pause for a certain period of time) is triggered.
Due to the event handling nature of the system, there is no busy waiting or sleeping the JavaFX thread, instead, you get notified and can take action when the event is fired.

There is an example of a timeline based approach here:


But, because there are higher-level APIs built for media processing, this is even simpler.


First, for playing beep type sounds, you can use a simpler API than Media, AudioClip is built for that:

If you want to repeat the same sound more than once, then you can set the cycle count on the audio clip:


Now, sometimes it is a good idea to use the richer API and functionality of the Media classes rather than an AudioClip.  For example, when the Media being played is pretty long and should be buffered (unlike an AudioClip which can load the entire media into memory), or when you need the extra functionality provided by the Media API.

One such example is the double beep situation you provide in your follow-up question, where you are playing one sound, then playing another different sound after the first sound completes.
Rather than trying to do a busy wait pause of the JavaFX application thread which hangs your app, listen for an event which signals that the first media has finished playing, and use that event to trigger playing the second media.


You note:
> I also consider using "aplay" system call cause so far this approach is working best on Linux
My guess is that using system calls for this kind of thing is probably not a good idea. 
You lose platform independence and you end up re-inventing the wheel because there is already decent media playback support in JavaFX.

3 months ago
Please provide the code you have .
That will make it easier to answer.
3 months ago
See: "Sample for accessing a local database from JavaFX."
3 months ago
> How do i change this to work outside events because i need to use there event to getSource ?

Can you provide an example of where you would like to do this outside the context of the event?
Perhaps a description of the use-case or a code snippet or mcve ( with a comment in it, "// how do I change scene here...".
3 months ago
Take a look at how the standard JavaFX alerts handle this.
Perhaps you can use a similar construct of returning an Optional ButtonType from a showAndWait method defined on the alert.

Here is an example with an Alert:

Code is from:

Or you could instantiate or extend Dialog and make use of its existing ButtonType returning logic and other functionality if that is appropriate for you.
Instantiating a Dialog is what I would recommend if that fits well into your application.
To see how to do this, look at the "Custom Login Dialog" section provided in the makery dialog tutorial link I provided.
And, yeah, I realize the Dialog API is a bit strange and would take some time to get used to.  But it might be worth investing that time in this case in order to be able to make use of the built-in functionality which Dialogs provide.
4 months ago
> trying to learn and use that and have been quite frustrated. Most of the examples I find and copy/paste into my editor don't work - error all over the place.

The following tutorial from Makery may help:


>  All in the world I want to do is have a simple dialog box come up with Ok/Cancel buttons

Sample code for showing a Confirmation Alert:

Makery provide further examples:


> It seems that the JavaFX forms (scenes? stages? windows? whatever they're called) created by FXML/Scene builder, don't want to work except in the context of a JavaFX "Application" - that is, a class that extends "Application". Is this correct?

No, that's not really right.  The FXMLLoader loads FXML to create a hierarchy of nodes which can be placed in the Scene Graph (the Oracle tutorial "Working with the Scene Graph" explains what that is).  FXML does not create scenes, stages or windows.  The code that backs an FXML form would go in a controller class.  A controller class would never extend Application.  An Application could create invoke the FXMLLoader to load an FXML (which generates the associated nodes and invokes initialization logic in the controller). 

You can see the structure used in the Oracle JavaFX tutorial:

* "Using FXML to Create a User Interface"

That tutorial links to which contains full code for the tutorial.

> In addition, I can't get it to work except within (or called from) the "start" method. Is that right?

In a way.  Generally an Application with a start method is the entry point for a JavaFX app, in the same way that a main class in Java with a static main method is the entry point for a standard Java app.  This is demonstrated in the Oracle tutorial "Hello World, JavaFX Style".  That is pretty much the JavaFX equivalent of a typical Java hello world program: .  A JavaFX program only has a single Application class which is invoked when the program is run (the same way the Java launcher only invokes the static main method once).  Once the application is launched it can instantiate other classes and execute code in them, so not all code needs to be in the start method.

There are other ways you can launch JavaFX functionality (e.g. a JFXPanel embedded in a Swing application), but as a beginner, you should not be using them.

> Can I mix FX with the Swing stuff?

Yes, you can, but don't do it.  Mixing JavaFX and Swing only makes sense if you have a large Swing application in which you want to embed a bit of JavaFX functionality or if you have a large JavaFX application in which you want to embed a complex existing Swing component (such as a Swing based PDF viewer for example).  As you are just starting out, neither of those situations will apply to you.  There are numerous considerations in mixing JavaFX and Swing code, which can tend to make it tricky (e.g. the UI of JavaFX and Swing components will have a different look and feel, care must be taken with threading as JavaFX and Swing run on different threads, etc).

Of course, you don't need to use Java to use JavaFX, you can use a scripting language if you prefer (which in some cases, some people may feel requires less unnecessary syntax and overhead).  For example here is the code example from above, but written in JavaScript:

You run it with the following command (assuming the code is saved to a file named confirm.js):

That runs the Nashorn JavaScript launcher and interpreter, passing the -fx argument to launch a JavaFX script.  The launcher knows it is a JavaFX app and runs the script inline.  It needs no start() method because the -fx switch already told the launcher that it is starting a JavaFX app.  For more info see:

I don't really recommend you write your JavaFX apps in JavaScript though... you won't get a lot of forum support for doing that if you have any questions about it.
4 months ago
Find out which java you are using by running:

$ java -version
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

I showed the sample output from my Mac, which is using Oracle JDK 9 by default.

If the output shows openjdk, rather than "Java HotSpot", then you are using an openjdk distribution provided for Ubuntu and not Oracle JDK.
By default (as far as I know), the Ubuntu openjdk installation does not include JavaFX, but instead uses a separate package which it calls openjfx:
You can install this using:
  sudo apt-get install openjfx
NOTE: you don't need to run that command if you are using Oracle JDK as Oracle JDK should have JavaFX included as long as you have installed the standard Oracle JDK
and not the server only version (which would be unlikely).

I'd advise using an IDE over basic VIM.  You can certainly get stuff done with VIM and the command line, but you will probably be more productive (in the end ;-) with an IDE.
One thing an IDE will do is make it easier to run basic builds on projects as it knows all of the code in the project and can build it for you.  Without an IDE, you will want to look
into using build tools such as Maven as soon as you start developing projects which are more than one or two files and are split across multiple packages.  There is a bit of learning
curve to tools like Maven, which I would advise you avoid until you really need them.

I'd advise using Intellij Idea over Netbeans.  I just personally like it a little better.
If you use Intellij Idea, you can configure the JDK it uses for development:
When you do that, for development, make sure you configure the IDE to use a JDK installation which includes JavaFX (for example Oracle JDK 9).

However, Netbeans is perfectly fine if you wish to use that.

Note that the Netbeans release binaries currently don't run on Java 9.  So, if you are using Netbeans, it is probably best to stick with Java 8 for now.
For context see:
That talks about building an incubating version which runs on JDK 9.  I wouldn't recommend that, as you don't need it.
Instead, just use the standard NetBeans JavaSE based download which would include an Oracle Java 8 version bundled.  This would have JavaFX support included.

4 months ago
I advise running a google search "rogue dungeon generator code java"
It will turn up lots of useful links, tutorials and code samples which should assist you in this task.

I also advise just getting the system to work with a text string or text file output that spits out your sample generated dungeons.
Once you have verified that that is working, then try integrating it into a graphical display system such as JavaFX and rendering as you wish.
4 months ago
> Yes I know with scene.Text and TextBoundsType.VISUAL but i need some css propertys that is not supported by scene.text control

There is no such thing, you need to do it in code.

> I don't understand your tip with text property listener, because i think scene.Text doesn't support TextBoundsTypes respectively nothing found in code javafx.scene.control.Labeled and javafx.scene.control.Label

Yeah, that wasn't very clear, sorry about that.

Here is some sample code.  It probably doesn't do exactly what you want, but it should demonstrate what I meant:
6 months ago