1

If I have a TableView with two columns, separate (not nested), then everything is okay when I try to rearrange them. If even ONE nested column exists however, it crashes when I try to rearrange something.

Here is my xml:

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

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="application.RecordsCtrl">
  <!-- TODO Add Nodes -->
  <children>
    <VBox id="VBox" alignment="CENTER" spacing="0.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
      <children>
        <TableView fx:id="table" editable="true" prefHeight="-1.0" prefWidth="-1.0">
          <columns>
            <TableColumn prefWidth="75.0" text="Column X">
              <columns>
                <TableColumn prefWidth="75.0" text="Name" fx:id="nameCol" />
                <TableColumn prefWidth="75.0" text="Age" fx:id="ageCol" />
              </columns>
            </TableColumn>
          </columns>
        </TableView>
        <Button mnemonicParsing="false" onAction="#editPerson" text="Edit" />
      </children>
    </VBox>
  </children>
</AnchorPane>

And here is what I am using from the controller class to set up the tableview:

@Override
   public void initialize(URL location, ResourceBundle resources) {
      obsList = FXCollections.observableArrayList();
      table.setItems(obsList);
      obsList.add(new Person("Riley", 40));
      obsList.add(new Person("Alex", 20));
      obsList.add(new Person("Jack", 30));
      nameCol.setCellValueFactory(new PropertyValueFactory<Person, String>(
            "name"));
      ageCol.setCellValueFactory(new PropertyValueFactory<Person, Integer>(
            "age"));
      nameCol.setCellFactory(TextFieldTableCell.<Person>forTableColumn());
      nameCol
            .setOnEditCommit(new EventHandler<CellEditEvent<Person, String>>() {

               @Override
               public void handle(CellEditEvent<Person, String> t) {
                  ((Person) t.getTableView().getItems()
                        .get(t.getTablePosition().getRow())).setName(t
                        .getNewValue());
               }
            });
   }

Does anyone know how to fix this? Rearranging columns is a must, and I need to get over this roadblock. Any help would be appreciated!

akhilless
  • 3,169
  • 19
  • 24
Toni_Entranced
  • 969
  • 2
  • 12
  • 29
  • How are you rearranging? By dragging in UI or by code? – Uluk Biy May 09 '14 at 06:52
  • Dragging from the UI. It works fine in the Scenebuilder's preview. In the actual project though, I am afraid that rearranging it caused corruption of the table columns. – Toni_Entranced May 09 '14 at 06:59
  • possible duplicate of [How to resolve nested column in tableview afetr update version of java-124 in javaFx?](http://stackoverflow.com/questions/21697949/how-to-resolve-nested-column-in-tableview-afetr-update-version-of-java-124-in-ja) – Uluk Biy May 09 '14 at 10:20

0 Answers0