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:



14 comments:

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

    ReplyDelete
  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.

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

    scene.getStylesheets().add("login.css");

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

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

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

    ReplyDelete
  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:

    scene.getStylesheets().add(Login.getClassLoader().getResource("login.css").toExternalForm());

    ReplyDelete
  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.

    if(sa.SearchByName(checkUser,checkPw,checkSk)){
    //lblMessage.setText("Congratulations!");
    //lblMessage.setTextFill(Color.GREEN);
    //lblMessage1.setText("Please Proceed.");
    //lblMessage1.setTextFill(Color.GREEN);
    System.out.println("Confirmed");
    proceed = true;
    if(proceed == true){
    System.out.println("I am in finally block");
    FileGUI fg = new FileGUI();

    try {
    fg.Callmain();
    System.out.println("Success");
    } catch (NullPointerException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }System.exit(0);
    }

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

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

    ReplyDelete
  11. Ofc :)

    http://zoranpavlovic.blogspot.com/2012/06/javafx-2-create-dialog-with-stage.html

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

    ReplyDelete