I'm working on a FXML app and I have ran into this error I can't see to resolve: The TreeViews produced by the attached code do not display their roots, even though to my best knowledge they should(the TreeViews themselves do show). Buttons and labels work fine.
On the off note, what exactly is the initialize() method supposed to do? Currently, I just write stuff in there sort of like they did in a tutorial and hope it shows up somehow. All I found about that method was the documentation on the Initializable interface, which didn't make me much wiser. Something about location and resources, but what exactly does that means in terms of Java? Those terms are too general to google for.
Also, the code is copied over from an earlier app that used Javafx only, with no FXML, and it wored fine there. So why doesn't it work now?
package sample;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import java.io.IOException;
public class FolderSyncerMainWindowController {
final String FOLDER_SYNCER = "FolderSyncer";
final String BROWSE = "Browse";
final String SOURCE = "Source...";
final String TARGET = "Target...";
final String COMPARE = "Compare";
final String CANCEL = "Cancel";
final String SYNCHRONIZE = "Synchronize";
final String COMPARING = "Comparing, this may take several minutes.";
final String SYNCHRONIZING = "Synchronizing, this may take several minutes.";
final String DONE = "Done.";
@FXML
private Label sourceLabel;
@FXML
private Label targetLabel;
@FXML
private Button sourceBrowseButton;
@FXML
private Button targetBrowseButton;
@FXML
private Button compareButton;
@FXML
private Button synchronizeButton;
@FXML
private TreeView sourceTreeView;
@FXML
private TreeView targetTreeView;
@FXML
private TreeItem sourceTreeViewRoot;
@FXML
private TreeItem targetTreeViewRoot;
public void initialize() {
sourceLabel.setText(SOURCE);
targetLabel.setText(TARGET);
sourceBrowseButton.setText(BROWSE);
targetBrowseButton.setText(BROWSE);
compareButton.setText(COMPARE);
synchronizeButton.setText(SYNCHRONIZE);
sourceTreeViewRoot = new TreeItem<>();
targetTreeViewRoot = new TreeItem<>();
sourceTreeViewRoot.setExpanded(true);
targetTreeViewRoot.setExpanded(true);
sourceTreeView = new TreeView<>(sourceTreeViewRoot);
targetTreeView = new TreeView<>(targetTreeViewRoot);
sourceTreeView.setShowRoot(true);
targetTreeView.setShowRoot(true);
}
}