0

I've got a problem with setVisible for ProgressBar, I wanna show a progressbar after clicking a Login button in my application, which will execute also a login to mysql database. The problem is that, the showing a progress bar is made as last thing during handling a button click.

public void handleLoginButton() {

    Connection connection = null;
    int wasError=0;
    loadingBar.setVisible(true);
    try {
        Class.forName("com.mysql.jdbc.Driver");

    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return;
    }

    try {
        connection = DriverManager
        .getConnection("jdbc:mysql://address","USER","PASSWORD");
    } catch (SQLException e) {
        wasError=1;
        System.out.println("Connection Failed! Check output console");
        //e.printStackTrace();
        return;
    }

    if (connection != null) {
        System.out.println("You made it, take control your database now!");

    } else {

        System.out.println("Failed to make connection!");

    }


}

How to make that the setVisible should be executed first?

TheOmniano
  • 61
  • 1
  • 7
  • 1
    My guess: you're not using background threading to do a long-running bit of code, the database access, and so you're tying up the GUI thread. – Hovercraft Full Of Eels Nov 15 '15 at 17:32
  • 3
    For more information for using backgrounds threads with database queries go through [JavaFX - Background Thread for SQL Query](http://stackoverflow.com/questions/14878788/javafx-background-thread-for-sql-query) and the extremely well explained answer to [Using threads to make database requests](http://stackoverflow.com/a/30250308/1759128) – ItachiUchiha Nov 15 '15 at 17:43

0 Answers0