3
I’m starting at Javafx and I’m having doubts.
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 the bdPrincipal
to add to 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;
}
}
Your title doesn’t match your question. Actually you want to know how to get the classes to communicate, right? Also, do you have doubts about creating Tableview? For example, if they were in the same class, you would know how to solve the problem?
– Math
Yes, perhaps my doubt can be dismembered. I will change the title.
– lucioam
Okay. I just didn’t understand one thing, you know so create Tableview?
– Math
Yes, I believe you know, but class communication is that I’m having a hard time.
– lucioam