Thursday, May 31, 2012

JavaFX 2: Create Nice Login Form

In this JavaFX tutorial I will design a nice looking Login Form with JavaFX 2 and CSS. It's clasic login form with username and password, and login button. In order to follow this tutorial I strongly recommend you to check these tutorials below:
Username: JavaFX2
Password: password

You can enter this information above and click on Login button. It will tell you with a little message that login is successful, but if you enter wrong information, it will tell you with a little message that login isn't successful.

The final output screenshot of this tutorial will be like below image.
JavaFX 2 Login Form
JavaFX 2 Login Form
Here is Java code of our example:

In order to style this application properly you'll need to create login.css file in /src folder of your project.
If you dont know how to do that, please check out JavaFX 2: Styling Buttons tutorial.
--> Here is CSS code of our example:

Thats'all folks for this tutorial, if you have any comments or problems, feel free to comment. If you like this tutorial, you can check out more JavFX 2 tutorials on this blog.

You might want to take a look at these tutorials below:


  1. Great! I've been looking for some cool JavaFX login form today! :)

  2. I hope that this tutorial will help you. If you have some problems with creating login form, let me know by leaving a comment.

    Feel free to share tutorial, and to check some other JavaFX tutorials on this blog.

  3. hi, line 117, the shorter version works fine for me,


  4. Cool, I tried the same, but I failed.

  5. I used JDK 7U5 with FX 2.1 SDK and e(fx)clipse,

  6. Thanks for the info, I must try e(fx)clipse.

  7. Hi,

    In the current version of JavaFX2 (2.1) loading the css with the getClass() does not work. If you replace it by the actual name of the class it does.

    So loading the login.css works if you code it like this:


  8. When I try to call a program written in java using java 7 U 5 which initiates jFileChooser, the login program hangs. I've tried to debug it, seems like a I might have hit a dead end.

    //lblMessage1.setText("Please Proceed.");
    proceed = true;
    if(proceed == true){
    System.out.println("I am in finally block");
    FileGUI fg = new FileGUI();

    try {
    } catch (NullPointerException e) {
    // TODO Auto-generated catch block
    } catch (IOException e) {
    // TODO Auto-generated catch block

  9. figured it out seems the Stage needs to be closed before calling jfilechooser class

  10. hi , can you please tell me how to navigate to another window ( scene ) by clicking the button login?

  11. Ofc :)

  12. Great code.....
    Java use css in client based application thats great...

  13. Assuming CSS and Class are in the same package : scene.getStylesheets().add(getClass().getResource("login.css").toString());

  14. Amusing. user Interface like web version in Client based Application