JavaFx tableview和tablecolumn中有两个不同的类

时间:2018-07-10 11:09:36

标签: java javafx

我的问题是我有两个不同的类:“书”和“用户”。 我想在单击“显示所有用户”按钮后在表中显示“书籍”,然后在单击“显示所有用户”按钮后在同一表中的所有用户。我不知道应该在tableview和tablecolumn中输入哪种类型。

我可以用什么代替“?” ?

public class WorkerPaneController implements Initializable {

@FXML
private TableView<?> tab;

@FXML
private TableColumn<?, ?> c3;

@FXML
private TableColumn<?, ?> c4;

@FXML
private TableColumn<?, ?> c5;

@FXML
private TableColumn<?, ?> c6;

@FXML
private Button test;

@FXML
private ComboBox<String> wybor;

@FXML
private Button show;

@FXML
private TableColumn<Data, ?> c1;

@FXML
private TableColumn<?, ?> c2;

@Override
public void initialize(URL location, ResourceBundle resources) {
    // TODO Auto-generated method stub

this.wybor.getItems().addAll("Książek", "Egzemplarzy", "Czytelników", 
"Pracowników");

}

@FXML
public void ChangeScene(ActionEvent event) throws IOException {

    Parent userMenu = 
FXMLLoader.load(getClass().getResource("/LibDB/view/UserPane.fxml"));

    Stage s = new Stage();
    s.setTitle("test");
    s.setScene(new Scene(userMenu));
    s.show();
}

@FXML
public void pokaz(ActionEvent event) throws IOException {
    if (wybor.getValue() != null) {
        switch (this.wybor.getValue()) {
        case "Czytelników":
            c1.setText("id_czytelnika");
            c2.setText("Imie");
            c3.setText("Nazwisko");
            c4.setText("Wiek");
            c5.setText("PESEL");
            c6.setText("id_adresu");
            break;
        case "Pracowników":
            c1.setText("id_czytelnika");
            c2.setText("Imie");
            c3.setText("Nazwisko");
            c4.setText("Wiek");
            c5.setText("PESEL");
            c6.setText("id_adresu");
            break;
        case "Książek":
            c1.setText("id_ksiazki");
            c2.setText("Tytul");
            c3.setText("Ilosc stron");
            c4.setText("ISBN");
            c5.setText("Rok Wydania");
            c6.setText("id_wydawnictwa");
            break;
        case "Egzemplarzy":
            c1.setText("id_egzemplarza");
            c2.setText("Numer katalogowy");
            c3.setText("id_Typ okladki");
            c4.setText("Numer ksiazki");
            c5.setText("opis");
            c6.setText("Dostepnosc");
            break;
        }
    } else {
        System.out.println("test");
    }

}

public void initPracownikow() {

    // c1.setCellValueFactory(data ->
    // data.getValue().getUzytkownicy().get(0).getImieProperty());
}
}

0 个答案:

没有答案