1. java
  2. android
  3. c#
  4. .net
  5. javascript
  6. php
  7. jquery
  8. html
  9. sql

javafx tableView

Amigos, o que etá de errado nesse código que a table não é preenchida? alguém pode me auxiliar

FXML

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.image.*?>
<?import javafx.scene.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>


<AnchorPane id="panel" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="606.0" prefWidth="624.0" style="-fx-background-color: white;" xmlns="http://javafx.com/javafx/8" 
xmlns:fx="http://javafx.com/fxml/1" fx:controller="br.com.farmacia.controller.Controle">
   <children>
      <TextField id="txValor" layoutX="239.0" layoutY="196.0" prefHeight="25.0" prefWidth="260.0">
         <effect>
            <InnerShadow blurType="ONE_PASS_BOX" choke="0.57" color="#0000002c" />
         </effect>
      </TextField>
      <ComboBox id="edtCombo" layoutX="25.0" layoutY="196.0" prefHeight="25.0" prefWidth="187.0" promptText="Escolha..." />
      <Label layoutX="131.0" layoutY="24.0" text="Farmacia" textFill="#40bc5a">
         <font>
            <Font name="Arial" size="48.0" />
         </font>
      </Label>
      <ImageView disable="true" fitHeight="150.0" fitWidth="200.0" focusTraversable="true" layoutX="424.0" layoutY="4.0" nodeOrientation="INHERIT" opacity="0.32" pickOnBounds="true" preserveRatio="true">
         <image>
            <Image url="br/com/farmacia/image/Enfermagem.jpg" />
         </image>
      </ImageView>
      <TableView id="edtTable" layoutX="25.0" layoutY="271.0" prefHeight="274.0" prefWidth="573.0">
        <columns>
          <TableColumn id="columnId" prefWidth="34.0" text="ID" />
          <TableColumn id="columnNome" prefWidth="176.0" text="Nome" />
            <TableColumn id="columnCategoria" prefWidth="130.0" text="Categoria" />
            <TableColumn id="columnSintomas" prefWidth="231.0" text="Sintomas" />
        </columns>
      </TableView>
      <Button id="edtPesquisar" layoutX="518.0" layoutY="196.0" mnemonicParsing="false" text="Pesquisar">
         <effect>
            <InnerShadow color="#3075340a" />
         </effect>
      </Button>
   </children>
   <effect>
      <InnerShadow color="#15bbd6" />
   </effect>
   <cursor>
      <Cursor fx:constant="CLOSED_HAND" />
   </cursor>
</AnchorPane>

MAIN:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.image.*?>
<?import javafx.scene.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>


<AnchorPane id="panel" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="606.0" prefWidth="624.0" style="-fx-background-color: white;" xmlns="http://javafx.com/javafx/8" 
xmlns:fx="http://javafx.com/fxml/1" fx:controller="br.com.farmacia.controller.Controle">
   <children>
      <TextField id="txValor" layoutX="239.0" layoutY="196.0" prefHeight="25.0" prefWidth="260.0">
         <effect>
            <InnerShadow blurType="ONE_PASS_BOX" choke="0.57" color="#0000002c" />
         </effect>
      </TextField>
      <ComboBox id="edtCombo" layoutX="25.0" layoutY="196.0" prefHeight="25.0" prefWidth="187.0" promptText="Escolha..." />
      <Label layoutX="131.0" layoutY="24.0" text="Farmacia" textFill="#40bc5a">
         <font>
            <Font name="Arial" size="48.0" />
         </font>
      </Label>
      <ImageView disable="true" fitHeight="150.0" fitWidth="200.0" focusTraversable="true" layoutX="424.0" layoutY="4.0" nodeOrientation="INHERIT" opacity="0.32" pickOnBounds="true" preserveRatio="true">
         <image>
            <Image url="br/com/farmacia/image/Enfermagem.jpg" />
         </image>
      </ImageView>
      <TableView id="edtTable" layoutX="25.0" layoutY="271.0" prefHeight="274.0" prefWidth="573.0">
        <columns>
          <TableColumn id="columnId" prefWidth="34.0" text="ID" />
          <TableColumn id="columnNome" prefWidth="176.0" text="Nome" />
            <TableColumn id="columnCategoria" prefWidth="130.0" text="Categoria" />
            <TableColumn id="columnSintomas" prefWidth="231.0" text="Sintomas" />
        </columns>
      </TableView>
      <Button id="edtPesquisar" layoutX="518.0" layoutY="196.0" mnemonicParsing="false" text="Pesquisar">
         <effect>
            <InnerShadow color="#3075340a" />
         </effect>
      </Button>
   </children>
   <effect>
      <InnerShadow color="#15bbd6" />
   </effect>
   <cursor>
      <Cursor fx:constant="CLOSED_HAND" />
   </cursor>
</AnchorPane>

Controle:

public class Controle implements Initializable {

    @FXML
    private TextField txValor;

    @FXML
    private Button btPesquisar;

    @FXML
    private TableView<ItensTable> edtTable;

    @FXML
    private TableColumn<ItensTable, Integer> columnId;

    @FXML
    private TableColumn<ItensTable, String> columnNome;

    @FXML
    private TableColumn<ItensTable, String> columnCategoria;

    @FXML
    private TableColumn<ItensTable, String> columnSintomas;

    private ObservableList<ItensTable> listRemedio = FXCollections.observableArrayList();

    public void initialize(URL arg0, ResourceBundle arg1) {

        initComponente();
        initTable();

    }

    private void initComponente() {

        columnId.setCellValueFactory(new PropertyValueFactory<ItensTable, Integer>("id"));
        columnNome.setCellValueFactory(new PropertyValueFactory<ItensTable, String>("nome"));
        columnCategoria.setCellValueFactory(new PropertyValueFactory<ItensTable,String>("categoria"));
        columnSintomas.setCellValueFactory(new PropertyValueFactory<ItensTable, String>("Sintomas"));

    }

    private void initTable(){

        CarregaMedicamento load = new CarregaMedicamento();
        load.addMedicamentos(new Medicamentos(1, "Monuril", "Antibiotico",
                "Infeccao"), new Medicamentos(1, "teste", "teste", "teste"));

        for (Medicamentos m : load.getMedicamento()) {

            listRemedio.add(new ItensTable(m.getId(), m.getNome(), m
                    .getCategoria(), m.getSintomas()));
        }

        edtTable.getItems().addAll(listRemedio);
    }

}

ERRo

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
    at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(Unknown Source)
    at com.sun.javafx.application.LauncherImpl$$Lambda$48/1732398722.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException: 
/D:/DOUGLAS/workpace_javaFx/Farmacia/bin/br/com/farmacia/css/Tela.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at br.com.farmacia.principal.Main.start(Main.java:20)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Unknown Source)
    at com.sun.javafx.application.LauncherImpl$$Lambda$51/1743635185.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$$Lambda$45/1051754451.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$$Lambda$47/1285769662.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$$Lambda$46/1775282465.run(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
    at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source)
    ... 1 more
Caused by: java.lang.NullPointerException
    at br.com.farmacia.controller.Controle.initComponente(Controle.java:53)
    at br.com.farmacia.controller.Controle.initialize(Controle.java:46)
    ... 23 more
Exception running application br.com.farmacia.principal.Main
  • Bom dia poderia postar o main e os fontes acima completos? Gostaria de tentar rodar para ver o que pode esta acontecendo.

    msartor   24 de nov de 2014
  • Adicionei os main, o FXML e o controle.

    Find Java   24 de nov de 2014
  • primeira coisa sem muito olhar o fonte eu diria não de new nos objetos da tela, o @FXML serve para que o proprio javafx inicialize a variavel para voce, faz um bindable do componente visual com a sua variavel, a primeira vista isso já esta errado vou tentar identificar outras coisas

    Cristian Urbainski   24 de nov de 2014
  • https://docs.oracle.com/javafx/2/ui_controls/table-view.htm

    nesse link tem um tutorial completo, outra coisa que faltou vou voce dizer para a coluna da tabela que informação ela exibe firstNameCol.setCellValueFactory( new PropertyValueFactory<Person,String>("firstName") );

    ai então ira funcionar, testa ai e nos da um retorno

    Cristian Urbainski   24 de nov de 2014
  • Então cristian, o new dei pq está dando "java.lang.NullPointerException" mais testar isso que vc falou por ultimo

    Find Java   24 de nov de 2014
Mostrar todos os 9 comentários>
  1. Você vai ver essas setas em qualquer página de pergunta. Com elas, você pode dizer se uma pergunta ou uma resposta foram relevantes ou não.
  2. Edite sua pergunta ou resposta caso queira alterar ou adicionar detalhes.
  3. Caso haja alguma dúvida sobre a pergunta, adicione um comentário. O espaço de respostas deve ser utilizado apenas para responder a pergunta.
  4. Se o autor da pergunta marcar uma resposta como solucionada, esta marca aparecerá.
  5. Clique aqui para mais detalhes sobre o funcionamento do GUJ!

1 resposta

Não é a resposta que estava procurando? Procure outras perguntas com as tags java javafx estrutura-de-dados ou faça a sua própria pergunta.