2016-12-24 13 views
-1

私のテーブルを作成する方法が見つからないようです。(私はそれらをseperatly見ると、私observebleListそれが動作するオブジェクト、それだけでinported私のデータを追加しないでください....私のテーブルビューにJava fxを埋め込むことはできません

This is my Controller: 
package Interface; 
import java.net.URL; 
import java.util.ArrayList; 
import java.util.ResourceBundle; 
import javafx.application.Platform; 
import javafx.collections.FXCollections; 
import javafx.collections.ObservableList; 
import javafx.event.ActionEvent; 
import javafx.fxml.FXML; 
import javafx.fxml.Initializable; 
import javafx.scene.control.TableColumn; 
import javafx.scene.control.TableView; 
import javafx.scene.control.cell.PropertyValueFactory; 
import javafx.scene.control.cell.TextFieldTableCell; 
public class ControllerForFinalPoint implements Initializable { 
    String id ; 
    String x ; 
    String y ; 
    String z ; 
    public void exitApplication(ActionEvent exitApplication) { 
     Platform.exit(); 
    } 
    public void intoarcere (String id, String x, String y, String z) { 
     this.id = id; 
     System.out.println(id); 
     this.x = x; 
     System.out.println(x); 
     this.y = y; 
     System.out.println(y); 
     this.z = z; 
     System.out.println(z); 
    } 

    @FXML 
    private TableView<MyPointFinal> tableCoord2; 
    @FXML 
    private TableColumn<MyPointFinal, String> Id; 
    @FXML 
    private TableColumn<MyPointFinal, String> X; 
    @FXML 
    private TableColumn<MyPointFinal, String> Y; 
    @FXML 
    private TableColumn<MyPointFinal, String> Z; 

    ObservableList<MyPointFinal> data = FXCollections.observableArrayList(
        new MyPointFinal(id, x, y, z)); 

    @Override 
    public void initialize(URL location, ResourceBundle resources) { 

     Id.setCellValueFactory(new PropertyValueFactory<MyPointFinal, String>("Id")); 
     Id.setCellFactory(TextFieldTableCell.forTableColumn()); 
     X.setCellValueFactory(new PropertyValueFactory<MyPointFinal, String>("X")); 
     X.setCellFactory(TextFieldTableCell.forTableColumn()); 
     Y.setCellValueFactory(new PropertyValueFactory<MyPointFinal, String>("Y")); 
     Y.setCellFactory(TextFieldTableCell.forTableColumn()); 
     Z.setCellValueFactory(new PropertyValueFactory<MyPointFinal, String>("Z")); 
     Z.setCellFactory(TextFieldTableCell.forTableColumn()); 
     tableCoord2.setItems(data); 

    } 

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

<?import javafx.scene.control.Button?> 
<?import javafx.scene.control.TableColumn?> 
<?import javafx.scene.control.TableView?> 
<?import javafx.scene.layout.AnchorPane?> 
<?import javafx.scene.layout.VBox?> 

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Interface.ControllerForFinalPoint"> 
    <children> 
     <TableView fx:id="tableCoord2" editable="true" prefHeight="558.0" prefWidth="600.0"> 
     <columns> 
      <TableColumn fx:id="Id" prefWidth="75.0" text="Name" /> 
      <TableColumn fx:id="X" prefWidth="150.0" text="X" /> 
      <TableColumn fx:id="Y" prefWidth="150.0" text="Y" /> 
      <TableColumn fx:id="Z" prefWidth="150.0" text="Z" /> 
     </columns> 
     </TableView> 
     <AnchorPane prefHeight="59.0" prefWidth="700.0"> 
     <children> 
      <Button layoutX="118.0" layoutY="34.0" mnemonicParsing="false" text="Save" AnchorPane.bottomAnchor="17.0" AnchorPane.leftAnchor="325.0" AnchorPane.rightAnchor="325.0" AnchorPane.topAnchor="17.0" /> 
     </children> 
     </AnchorPane> 
     <AnchorPane prefHeight="38.0" prefWidth="600.0" /> 
    </children> 
</VBox> 

答えて

0

私は問題は方法は、あなたが考える順序で呼び出されていないということだと思います。まず、JavaFXのインスタンスを作成し、したがって、変数 'id'、 'x'、 'y'、 'z'を使用してObservableList dataフィールドを初期化してから、上記のObservableListを使用しているinitialize()メソッドを呼び出すと、intoarcere()以前にObseを構築するために使用されたフィールドrvableListの内容....(うおops)。

したがって、実際のMyPointFinalインスタンスは(コンテンツのログに記録されたときに)確認されますが、すべての値が 'null'なので何も表示されません。

intoarcere()を次のように変更すると結果が表示されます。

public void intoarcere (String id, String x, String y, String z) 
{ 
    this.data.add(new MyPointFinal(id, x, y, z)); 
} 

ps。現在、大文字と小文字の 'x'、 'y'、 'z'の両方で変数名を使用しています。一般的な命名規則に対して「PascalCased」変数名だけでなく、(他の人にとっても、しばらくしてから)混乱します。あなた自身のために名前を変更しようとしてください。

+0

tx、それはそれほど問題ではありませんでした。私は私のリストに入ることを奨励していた私のデータがnullであることを知りました。私は他の方向にmethodeを呼び出す必要があります。 "PS"を心に留めてくれてありがとう。 –

関連する問題