This time it will be a short-long article about JDK8/JavaFX8 and Ubuntu. In recent days I decided to play with several new libraries which require Java 8 and controlsfx.org is one of them. Sadly, there won’t be any backport to the current version of javafx. But I understand it.
- Firstly, you have to go http://jdk8.java.net/download.html and download & install the latest version of Java 8. See point #3.
- Do the same with “special version” of Eclipse + EfxClipse + Java8 created from Tom
- I use the latest ubuntu. For java 8 I strongly recommend to read and use this tutorial. Otherwise no guarantee that it will work.
- You can of course install other linux-javafx-software such as SceneBuilder (they provide even .deb package !!!! => no problems to install at all) or Scenic View
To play with libraries such as controlsfx you must have that eclipse. Make absolutely sure that things like compiler compliance level is set to 1.8 (beta) (see pic). This is very important step. You have also to make sure that eclipse is linked to the right folder of your java in ubuntu. Mine is “/usr/lib/jvm/java-8-oracle”. After we had done that we can start rebuilding + reconfiguring the project for the java 8.
Now you ready to play with the newest java(fx) 8.
Dialog uses ControlsFX library
Today I will describe how I replaced a dialog (“about” section in the menu) with classes from the controlsfx library.
I changed just several lines of code. As I once said in my tweet, the documentation for this library is an example for all documentations ever created. Therefore, you won’t have problems to understand it very quickly.
— John Malc (@Malcjohn) July 26, 2013
Sadly, this is not the case for the current javafx api docs nor for the javafx 8 api docs. In my example I just have to use a Method chaining. There is no trick for that. Here is the all documentation which is needed for creating a new dialog.
Dialogs.create() .title(" title ") .message( "information") .lightweight() .showInformation()
This is a part of code which makes it happen. Nothing more, nothing less. The dialog you created will display a message, a title and it will be also an “information dialog”. Not an error or some other. BTW, there a lot of them to choose. .
lightweight() means that the dialog will be “rendered within the scenegraph and can’t leave the window”. Very nice feature.
Now, initially I had problems with java 8 and loading of fxml files & their controllers. It didn’t just work. I taught that there are some changes, but in api docs of javafx 8 doesn’t seem that something was changed. Then, I solved that problem. “Account.fxml” and “account.fxml” are different and there are fucking differences!!!! Here is an example of doing that. I know that there are easier ways to do so.
FXMLLoader loader = new FXMLLoader(); Parent root = (Parent) loader.load(getClass().getResource( "/res/account.fxml").openStream()); Stage dialogStage = new Stage(); dialogStage.getIcons().add(new Image("/res/account.png")); dialogStage.setTitle("Edit Account"); dialogStage.initModality(Modality.NONE); dialogStage.initOwner(primaryStage); Scene scene = new Scene(root); dialogStage.setScene(scene); AccountController ac = loader.getController(); ac.setNewAccount(dialogStage); dialogStage.show();
As you can see there are no differences compering to javafx 2. Standard loading of a .fxml file and passing it through scene and then stage.
At the moment I have paused the development because if would create sth. like an address book, I will need to rework that completely. Means creating whole new UI. Therefore, I have tried to work with java 8 (lambdas etc. wouldn’t be a benefit here) and I want to see that to be released already. I can’t wait.
In the near future I want to try something new, because of that I think, generally speaking, I won’t work so actively that I have worked in recent weeks.