Reputation: 149
Looking to open a new Scene when a string value in a JavaFX table cell is "Chrome" and when that cell is being right clicked. When I click on any cell in the application column it doesn't output second button.
@Override
public void handle(MouseEvent event) {
MouseButton button = event.getButton();
if (button == MouseButton.PRIMARY) {
System.out.println("primany buton");
} else if (button == MouseButton.SECONDARY && applicationname_column.getCellValueFactory().toString().contentEquals("Chrome"))
{
System.out.println("second button");
Parent Chromepage = null;
try {
Chromepage = FXMLLoader.load(getClass().getResource("Chrome_logs.fxml"));
} catch (IOException e) {
e.printStackTrace();
}
Stage stage = new Stage();
Scene scene = new Scene(Chromepage);
stage.setScene(scene);
URL url = this.getClass().getResource("DarkTheme.css");
if (url == null) {
System.out.println("Resource not found. Aborting.");
System.exit(-1);
}
String css = url.toExternalForm();
scene.getStylesheets().add(css);
stage.setTitle("Chrome Logs");
stage.show();
} else if (button == MouseButton.MIDDLE) {
System.out.println("middle button");
}
}
});
return cell;
}
}
Upvotes: 0
Views: 350
Reputation: 49185
You can retrieve the item that the cell is rendering, and check its value. So do
...
else if (button == MouseButton.SECONDARY && "Chrome".equals(cell.getItem()))
{
...
}
...
Upvotes: 1