Reputation: 13
I have a tableview with a model class for it. The table view shows all groups that a user can join and I would like to have a mouseclick event on the row of a tableView that a user clicks. This will change a text on a label to say if there is space in the group or not.
The problem that i am getting is "Caused by: javafx.fxml.LoadException: Error resolving onMouseClicked='#clickItem', either the event handler is not in the Namespace or there is an error in the script." I am using a scene builder and have declared the method to "On Mouse Clicked" and still getting the error.
Would be helpful if you can tell me a solution to be able to do this or fix the error. Thanks in advance.
public void showAvailability(MouseEvent event) {
selected = groupsTable.getSelectionModel().getSelectedItem();
boolean checkAvailability = checkSpaceInGroup(selected);
if(checkAvailability){
availabilityStatus.setText("Space in Group");
availabilityPane.setStyle("-fx-background-color: #" + "388e3c ");
}
else{
availabilityStatus.setText("NO SPACE");
availabilityPane.setStyle("-fx-background-color: #" + "ffcdd2 ");
}
}
Upvotes: 1
Views: 2139
Reputation: 992
You might have imported wrong library: (not sure without looking at the whole code)
import java.awt.event.??
instead of:
import javafx.event.??
However you can create an event from your Initialize method, on controller class, like this:
groupsTable.setOnMouseClicked((MouseEvent event) -> {
//your code goes here
}
In this case, MouseEvent is imported using:
import javafx.scene.input.MouseEvent;
Hope it helps!
Upvotes: 1