我一直在oracle.com上关注JavaFX TableView教程, https://docs.oracle.com/javase/8/javafx/user-interface-tutorial/table-view.htm
但我似乎无法让我的桌子填充,我试图做一个简单的密码管理器。
我为ObservableList做了一个简单的测试对象,但即使这样也不会出现。
这是我的证书'类:
import javafx.beans.property.SimpleStringProperty;
// Simple class for holding credentials
class Credentials {
private final SimpleStringProperty Username;
private final SimpleStringProperty URL;
private final SimpleStringProperty Password;
public Credentials(String x, String y, String z) {
this.URL = new SimpleStringProperty(x);
this.Username = new SimpleStringProperty(y);
this.Password = new SimpleStringProperty(z);
}
public String username(){ return Username.get(); }
public String url(){ return URL.get(); }
public String password(){ return Password.get(); }
}
这是我的应用程序类,
public class Crypt32Dec extends Application {
private TableView<Credentials> table = new TableView<Credentials>();
private ObservableList<Credentials> data = FXCollections.observableArrayList(new Credentials("test", "test", "test"));
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void start(Stage primaryStage) {
JDec dec = new JDec();
GridPane grid=new GridPane();
final Label label = new Label("Password Recovery Tool");
label.setFont(new Font("Arial", 20));
GridPane.setConstraints(label, 0, 0);
table.setEditable(true);
TableColumn URLCol = new TableColumn("URL");
URLCol.setMinWidth(100);
URLCol.setCellValueFactory(new PropertyValueFactory<>("URL"));
TableColumn UsernameCol = new TableColumn("Username");
UsernameCol.setMinWidth(100);
UsernameCol.setCellValueFactory(new PropertyValueFactory<>("Username"));
TableColumn PasswordCol = new TableColumn("Password");
PasswordCol.setMinWidth(200);
PasswordCol.setCellValueFactory(new PropertyValueFactory<>("Password"));
table.setMaxHeight(200);
table.setItems(data);
table.getColumns().addAll(URLCol, UsernameCol, PasswordCol);
GridPane.setConstraints(table, 1, 0);
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(10, 0, 0, 10));
vbox.getChildren().addAll(label, table);
grid.getChildren().add(vbox);
Button btn = new Button();
Button btn2 = new Button();
Button btn3 = new Button();
GridPane.setConstraints(btn, 2, 0);
btn.setText("Recover Local Passwords");
btn2.setText("Generate Password");
btn3.setText("Recover External Passwords");
grid.getChildren().addAll(btn, btn2);
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
ArrayList<Credentials> ChromeDetails = dec.ChromeDec();
ArrayList<Credentials> FirefoxDetails = dec.FirefoxDec();
for(Credentials Details : FirefoxDetails){
data.add(new Credentials(Details.url(), Details.username(), Details.password()));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GeneralSecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
btn2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(grid);
Scene scene = new Scene(root, 500, 550);
primaryStage.setTitle("Password Recovery Tool");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}