JavaFX: Tooltip - Can't get tooltip's to show at all


I'm in the middle of a project where i'm supposed to write a login system using JavaFX 2.0. And right now i'm trying to write a tooltip with a connection to the password field, but the tooltip NEVER shows at all.. I'm using the FXML-LoginDemo project from the 'javafx-samples-2.0.3'. And then I tried to use: example 19.1.

If you need more code to see this problem please say so.. because I don't really know where the problem is..

Here's my code so far:

package demo;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;

 * Login Controller.
public class LoginController {
    @FXML private TextField userId;
    @FXML private PasswordField password;
    @FXML private Label errorMessage;
    @FXML final Tooltip tooltip = new Tooltip();

    @FXML protected void processLogin(ActionEvent event) {

        tooltip.setText("\nYour password must be\n at least 8 characters in length\n");

        if(!App.getInstance().userLogging(userId.getText(), password.getText())){
            errorMessage.setText("Invalid username or password: " + userId.getText());
        //Replaces inputed password with an empty String.
3/20/2012 2:13:34 PM

Accepted Answer

Define an initialize method on the controller and, in that method, set the tooltip text and associate the tooltip with the password field. If you wait until the processLogin action is called to set the Tooltip, the scene has already been displayed and the user has already tried to login.

Also, you don't need to place the @FXML annotation in front of the Tooltip unless you are defining Tooltip properties in FXML, which is probably not necessary in this case.

3/20/2012 8:37:17 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow