I'm new to JavaFX and have encountered strange behaviour, firstly i will show my code
public class FreezeFX extends Application {
private VBox root;
private HBox btnContainer;
private Button addBtn, removeBtn;
private TableView<Action> actionsTable;
private TableColumn<Action, String> keywordCol, pathCol;
private ObservableList<FreezeFX.Action> actionList;
public static void main(String[] args){
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
setupUI(primaryStage);
bindData();
primaryStage.show();
}
private void setupUI(Stage stage) {
root = new VBox(10);
root.setPadding(new Insets(10));
btnContainer = new HBox(10);
addBtn = new Button();
addBtn.setText("Add Keyword");
removeBtn = new Button("Remove Keyword");
btnContainer.getChildren().addAll(addBtn, removeBtn);
root.getChildren().add(btnContainer);
actionsTable = new TableView<Action>();
keywordCol = new TableColumn<Action, String>();
keywordCol.setText("Keyword");
keywordCol.setCellValueFactory(new PropertyValueFactory<Action, String>("keyword"));
keywordCol.setPrefWidth(138);
pathCol = new TableColumn<Action, String>();
pathCol.setText("Path");
pathCol.setCellValueFactory(new PropertyValueFactory<Action, String>("path"));
pathCol.setPrefWidth(340);
actionsTable.getColumns().addAll(keywordCol, pathCol);
root.getChildren().add(actionsTable);
Scene scene = new Scene(root, 500, 500);
stage.setScene(scene);
stage.setTitle("Remote PC");
}
private void bindData(){
actionList = FXCollections.observableArrayList();
Action a1 = new Action("internet", "path1");
Action a2 = new Action("winrar", "path2");
actionList.addAll(a1,a2);
actionsTable.setItems(actionList);
}
public class Action{
private String keyword;
private String path;
public Action(String keyword, String path) {
this.keyword = keyword;
this.path = path;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}
}
Everything works fine without TableView, when I add TableView to my Scene I'm experiencing screen freezing (for about 2 seconds) then I've got a notification from Windows (Windows 10) saying "screen controller stopped responding but is working again" (my own translation from polish ;)) almost each time I run the program (yep almost, like 9 times out of 10). There aren't any errors in console, and problem occurs when I trie to click on a button, table, label etc inside my app window. Before the click, app works fine, it's type of server app and it's able to receive message from client and update UI, everything crashes when I click something as I mentioned earlier. And as I said, If I'm not adding TableView to my scene, everything works fine. Thanks in advance for help
---EDIT--- So I updated posted above code with minimal code needed to reproduce the problem. What I also noticed:
1) If I don't add btnContainer to the root everything works
2) If I add the btnContainer to the root, as in the code above BUT move this line actionsTable.setItems(actionList);
just under this line actionList = FXCollections.observableArrayList();
everything will work to, however the tableView is not refreshing it's content
---EDIT2---
3) If I firstly add actionsTable and than btnContainer it's working finen and actionsTable is updating itself when needed
I'm running Windows 10 on Toshiba S55-85312 with Intel HD Graphics 4600