I'm starting in JavaFX and I'm having second thoughts.
The main class creates an HBox with a button. This button has the action of creating a TableView
in the Center of bdPrincipal
. Only they are in different classes / packages.
What is the best way to search for bdPrincipal
to add addTabela()
?
BorderPane bpPrincipal;
public void start(Stage primaryStage) {
bpPrincipal = new BorderPane();
bpPrincipal.setLeft(Menu.addMenu());
scPrincipal = new Scene(bpPrincipal);
primaryStage.setScene(scPrincipal);
primaryStage.centerOnScreen();
primaryStage.setHeight(Screen.getPrimary().getVisualBounds().getHeight());
primaryStage.setWidth(Screen.getPrimary().getVisualBounds().getWidth());
primaryStage.show();
}
public class Menu {
public static HBox addMenu() {
HBox hbox = new HBox();
hbox.setPadding(new Insets(15, 12, 15, 12));
hbox.setSpacing(20);
hbox.setStyle("-fx-background-color: #336699;");
Button btnListar = new Button("Listar");
btnListar.setPrefSize(100, 20);
btnListar.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent evento) {
GestorFX.bpPrincipal.setCenter(addTabela());
}
});
hbox.getChildren().addAll(btnListar);
return hbox;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private static TableView addTabela()
{
TableColumn colCodigo = new TableColumn();
colCodigo.setText("Código");
colCodigo.setMinWidth(150);
colCodigo.setCellValueFactory(new PropertyValueFactory("clienteCodigo"));
TableColumn colFantasia = new TableColumn();
colFantasia.setText("Nome Fantasia");
colFantasia.setMinWidth(450);
colFantasia.setCellValueFactory(new PropertyValueFactory("clienteFantasia"));
TableColumn colRazao = new TableColumn();
colRazao.setText("Razão Social");
colRazao.setMinWidth(450);
colRazao.setCellValueFactory(new PropertyValueFactory("clienteRazao"));
TableView tabela = new TableView();
tabela.setItems(Negocio.Cliente.ListaCompleta());
tabela.getColumns().addAll(colCodigo, colFantasia, colRazao);
return tabela;
}
}