Boa tarde galera, tudo bem?
Atualmente comprei o livro da casa do código no qual ensina a como explorar melhor as API’s em Java.
O problema é que o código correspondente do livro está dando muito erro.
Pelo que percebi o problema seria com o Pacote Label e com a instância da Classe.
Segue meu código, e se algum puder me dar alguma ajuda seria de muito bom.
package application;
import java.awt.Insets;
import java.awt.Label;
import br.com.casadocodigo.livraria.produtos.Produto;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.stage.Stage;
import repositorio.RepositorioDeProdutos;
@SuppressWarnings({"unchecked", "rawtypes" })
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
Group group = new Group();
//690 - altura / 510 - largura
Scene scene = new Scene(group, 690, 510);
ObservableList<Produto> produtos =
new RepositorioDeProdutos().lista();
TableView<Produto> tableView = new TableView<>(produtos);
TableColumn nomeColumn = new TableColumn<>("Nome");
nomeColumn.setMinWidth(180);
nomeColumn.setCellValueFactory(
new PropertyValueFactory<>("nome"));
TableColumn descColumn = new TableColumn<>("Descrição");
descColumn.setMinWidth(230);
descColumn.setCellValueFactory(
new PropertyValueFactory<>("descrição"));
TableColumn valorColumn = new TableColumn<>("Valor");
valorColumn.setMinWidth(60);
valorColumn.setCellValueFactory(
new PropertyValueFactory<>("valor"));
TableColumn isbnColumn = new TableColumn<>("Isbn");
isbnColumn.setMinWidth(180);
isbnColumn.setCellValueFactory(
new PropertyValueFactory<>("isbn"));
tableView.getColumns().addAll(nomeColumn, descColumn, valorColumn, isbnColumn);
final VBox vbox = new VBox(tableView);
vbox.setPadding(new Insets(70, 0, 0, 10));
Label label = new Label("Listagem de Livros");
label.setFont(Font
.font("Lucida Grande", FontPosture.REGULAR, 30));
label.setPadding(new Insets(20, 0, 10, 10));
group.getChildren().addAll(label);
primaryStage.setScene(scene);
primaryStage.setTitle("Sistema da livraria com Java FX");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
os erros que estou tomando:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.Error: Unresolved compilation problems:
The method setPadding(javafx.geometry.Insets) in the type Region is not applicable for the arguments (java.awt.Insets)
The method setFont(java.awt.Font) in the type Component is not applicable for the arguments (javafx.scene.text.Font)
The method setPadding(Insets) is undefined for the type Label
The method addAll(Node...) in the type ObservableList<Node> is not applicable for the arguments (Label)
at application.Main.start(Main.java:58)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more
Exception running application application.Main