1

Using JavaFx 2 and Netbeans IDE 8.0 with Java 8. I am extracting data from a FileMaker database and adding it as a "Ticket" object to an observableArrayList (called "row" here). I am then passing that list to the table to show what has been found. I have the observableArrayList populated, but I cannot get it to display in the table.

I have my table view built in FXML:

<TableView fx:id="ticketData" layoutX="-3.0" layoutY="351.0" prefHeight="203.0" prefWidth="554.0">
                       <columns>
                          <TableColumn fx:id="ticket" editable="false" prefWidth="59.0" text="Ticket" />
                          <TableColumn fx:id="dates" prefWidth="72.0" text="Date(s)" />
                          <TableColumn fx:id="files" editable="false" prefWidth="114.0" text="File(s) Found" />
                          <TableColumn fx:id="notes" prefWidth="297.0" text="Notes" />
                       </columns>
                    </TableView>

My Java Class that has my setters/getters, etc:

    public  class Ticket 
    {
    private  SimpleStringProperty  ticketType;
    private  SimpleObjectProperty<Date>  executionDate;
    private  SimpleBooleanProperty gotFile;
    private  SimpleStringProperty  statusMessage;

    public Ticket(String tt, Date done, boolean gf, String stat)
    {
        this.ticketType = new SimpleStringProperty (tt);
        this.executionDate = new SimpleObjectProperty<Date>(done) {};
        this.gotFile = new SimpleBooleanProperty(gf);
        this.statusMessage = new SimpleStringProperty(stat);
    }


     public String getTicketType() {
        return ticketType.get();
    }
    public void setTicketType(String tt) {
        ticketProperty().set(tt);
    }
    public StringProperty ticketProperty() { 
         if (ticketType == null) ticketType = new SimpleStringProperty(this, "ticketType");
         return ticketType; 
     }

     public Date getExecutionDate() {
        return executionDate.get();
    }
    public void setExecutionDate(Date done) {
        executionDate.set(done);
    }
        public SimpleObjectProperty dateProperty() { 
         if (executionDate == null) executionDate = new SimpleObjectProperty(this, "executionDate");
         return executionDate; 
     }

    public boolean getGotFile(){
        return gotFile.get();
    }
    public void setGotFile(boolean gf){
        gotFile.set(gf);
    }
        public SimpleBooleanProperty gotProperty() { 
         if (gotFile == null) gotFile = new SimpleBooleanProperty(this, "gotFile");
         return gotFile; 
     }

    public String getStatusMessage() {
       return statusMessage.get();
   }
    public void setStatusMessage(String stat) {
        statusMessage.set(stat);
    }
        public StringProperty statusProperty() { 
         if (statusMessage == null) statusMessage = new SimpleStringProperty(this, "statusMessage");
         return statusMessage; 
     }
}

Method used to gather the resultset data I need from FileMaker:

public void accumulate(String type, Date essential, boolean got, String msg)
    {
        Ticket ticket;
        ticket = new Ticket(type, essential, got, msg);
        row.add(ticket);
    }

After I've completed my search for what I need I then in my controller, set my tableview ("ticketData" here), to hold the items, with each column having a CellValueFactory that correlates to the Ticket class.

ticketData = new TableView();

           ticket.setCellFactory(TextFieldTableCell.forTableColumn());
        ticket.setCellValueFactory(
                new PropertyValueFactory<>("ticketType"));


           dates.setCellFactory(TextFieldTableCell.forTableColumn());
           dates.setCellValueFactory(
                new PropertyValueFactory<>("executionDate"));

           files.setCellFactory(TextFieldTableCell.forTableColumn());
           files.setCellValueFactory(
                new PropertyValueFactory<>("gotFile"));

           notes.setCellFactory(TextFieldTableCell.forTableColumn());
           notes.setCellValueFactory(
                new PropertyValueFactory<>("statusMessage"));

        ticketData.getColumns().addAll(ticket,dates,files,notes);
        //System.out.println(Arrays.deepToString(row.toArray()));

        ticketData.setItems(row);

I can do a print on the observableArrayList and see the entries in it, but the tableview remains blank.

Any suggestions? Have I missed something? I'm at a loss.

BhushanK
  • 1,205
  • 6
  • 23
  • 39
senex_subconscious
  • 221
  • 2
  • 6
  • 14
  • 1
    You are creating a new `TableView` with `ticketData=newTableView()` and then populating that table instead of the one in your FXML. This is a duplicate of [JavaFX FileChooser Throws Error (probably easy fix, but still confused)](http://stackoverflow.com/questions/23094846/javafx-filechooser-throws-error-probably-easy-fix-but-still-confused) – James_D Aug 15 '14 at 14:44

1 Answers1

0

PropertyValueFactory<>("TicketType") should be ticketType, note the lower case. Same for all fields.

http://docs.oracle.com/javafx/2/api/javafx/scene/control/cell/PropertyValueFactory.html

brian
  • 10,619
  • 4
  • 21
  • 79
  • I had it like that originally and it didn't work. Changed it back just now to see if it would make a difference and nothing for it. My tableview is still blank :( – senex_subconscious Aug 15 '14 at 13:22
  • maybe you're not getting data from the db. – brian Aug 15 '14 at 13:43
  • I have the data printing out before it goes into the observableArrayList and before I pass it to the table view. There is definitely data there, which is the maddening part. – senex_subconscious Aug 15 '14 at 14:11
  • 1
    `ticketData = new TableView();` shouldn't be there. This is why you need a SSCE for people to test. I don't see where it's declared but there should be a `@FXML TableView ticketData` declaration somewhere. You're making a new table instead of using the one made in fxml. Same for the columns and every other fxml construct you use. – brian Aug 15 '14 at 14:40
  • 1
    I also have doubts about all the `TextFieldTableCell`'s without string converters, but that's another question. – brian Aug 15 '14 at 14:44
  • Yepp that was it, the new tableview declaration. And you are right the textfieldtablecells are/were an issue, but that is fixable, like you said with clever string converters. Thanks for your help! How should I accept this as solved when the answer ended up in the comments? – senex_subconscious Aug 15 '14 at 14:56