我已经复制了我的项目,并且已经从互联网上复制了一个代码,并且我遇到了这个问题:
错误Java:找不到符号 symbol:变量treeView 位置:类homme.Controller
错误出现在第二和第三行:
final TreeItem<User> root = new RecursiveTreeItem<User>(users, RecursiveTreeObject::getChildren);
treeView.getColumns().setAll(nameCol,ageCol,deptName);
treeView.setRoot(root);
treeView.setShowRoot(false);
这是控制器的所有代码:
package home;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import com.jfoenix.controls.JFXTreeTableColumn;
import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.layout.FlowPane;
import com.jfoenix.controls.JFXTreeTableView;
import com.jfoenix.controls.RecursiveTreeItem;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.util.Callback;
public class Controller implements Initializable {
@FXML
private VBox pnItems = null;
@FXML
private Button btnOverview;
@FXML
private Button btnOrders;
@FXML
private Button btnCustomers;
@FXML
private Button btnMenus;
@FXML
private Button btnPackages;
@FXML
private Button btnSettings;
@FXML
private Button btnSignout;
@FXML
private Pane pnlCustomer;
@FXML
private Pane pnlOrders;
@FXML
private Pane pnlOverview;
@FXML
private Pane pnlMenus;
@FXML
private JFXTreeTableView<?> treeView;
@Override
public void initialize(URL url, ResourceBundle rb) {
JFXTreeTableColumn<User, String> deptName = new JFXTreeTableColumn<>("Department");
deptName.setPrefWidth(150);
deptName.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<User, String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<User, String> param) {
return param.getValue().getValue().department;
}
});
JFXTreeTableColumn<User, String> ageCol = new JFXTreeTableColumn<>("Age");
ageCol.setPrefWidth(150);
ageCol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<User, String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<User, String> param) {
return param.getValue().getValue().age;
}
});
JFXTreeTableColumn<User, String> nameCol = new JFXTreeTableColumn<>("Name");
nameCol.setPrefWidth(150);
nameCol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<User, String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<User, String> param) {
return param.getValue().getValue().userName;
}
});
ObservableList<User> users = FXCollections.observableArrayList();
users.add(new User("Computer Department", "23", "CD 1"));
users.add(new User("Sales Department", "22", "Employee 1"));
users.add(new User("Sales Department", "22", "Employee 2"));
users.add(new User("Sales Department", "25", "Employee 4"));
users.add(new User("Sales Department", "25", "Employee 5"));
users.add(new User("IT Department", "42", "ID 2"));
users.add(new User("HR Department", "22", "HR 1"));
users.add(new User("HR Department", "22", "HR 2"));
final TreeItem<User> root = new RecursiveTreeItem<User>(users, RecursiveTreeObject::getChildren);
treeView.getColumns().setAll(nameCol,ageCol,deptName);
treeView.setRoot(root);
treeView.setShowRoot(false);
}
@FXML
private void filter(ActionEvent event) {
}
class User extends RecursiveTreeObject<User> {
StringProperty userName;
StringProperty age;
StringProperty department;
public User(String department, String age, String userName) {
this.department = new SimpleStringProperty(department);
this.userName = new SimpleStringProperty(userName);
this.age = new SimpleStringProperty(age);
}
}
public void handleClicks(ActionEvent actionEvent) {
if (actionEvent.getSource() == btnCustomers) {
pnlCustomer.setStyle("-fx-background-color : #1620A1");
pnlCustomer.toFront();
}
if (actionEvent.getSource() == btnMenus) {
pnlMenus.setStyle("-fx-background-color : #53639F");
pnlMenus.toFront();
}
if (actionEvent.getSource() == btnOverview) {
pnlOverview.setStyle("-fx-background-color : #02030A");
pnlOverview.toFront();
}
if(actionEvent.getSource()==btnOrders)
{
pnlOrders.setStyle("-fx-background-color : #464F67");
pnlOrders.toFront();
}
}
}