javaFXML联系人簿-将联系人信息添加到文本字段并建立新联系人

时间:2019-03-10 23:57:50

标签: java fxml

因此,我正在制作一本通讯录,并使用scenebuilder来为Java部分制作布局和netbeans。我已经做到了,因此边框窗格左侧的列表视图具有联系人姓名和拇指图像,并且边框窗格中央也有一个网格窗格,其文字说明了右侧文本字段中的内容它的。我正在尝试做的是使它具有我为联系人存储的信息,因此当您单击列表上的联系人姓名时,它将更新每个文本字段中的信息。我试图制作另一个列表,以为我可以调用数据,但我可以使它正常工作。

public class FXMLDocumentController {


@FXML
private ListView<Picture> picList;

@FXML
private ListView<Contact> Info;

@FXML
private GridPane contactSheet;

@FXML
private TextField fName;

@FXML
private TextField lName;

@FXML
private TextField eMail;

@FXML
private TextField Phone;

@FXML
private Button newContactButton;

private final ObservableList<Picture> pictures = FXCollections.observableArrayList();
private final ObservableList<Contact> CInfo = FXCollections.observableArrayList();

public void initialize(){
    pictures.add(new Picture("Dog One", "/Images/Dog1.jpg"));
    pictures.add(new Picture("Dog Two", "/Images/Dog2.jpg"));
    pictures.add(new Picture("Dog Three", "/Images/Dog3.jpg"));
    pictures.add(new Picture("Turtle One", "/Images/Turtle1.jpg"));
    pictures.add(new Picture("Turtle Two", "/Images/Turtle2.jpg"));
    CInfo.add(new Contact("Dog", "One", "Dog@bork.com", 1234567898));
    CInfo.add(new Contact("Dog", "Two", "Dog2@bork.com", 1235432136));
    CInfo.add(new Contact("Dog", "Three", "Dog3@bork.com", 1235432134));
    CInfo.add(new Contact("Turtle", "One", "Turtle@water.com", 1235432137));
    CInfo.add(new Contact("Turtle", "Two", "Turtle2@water.com", 1235432139));


    picList.setItems(pictures);

    picList.setCellFactory(
            new Callback<ListView<Picture>, ListCell<Picture>>(){
                @Override
                public ListCell<Picture> call(ListView<Picture> listView){
                    return new ImageTextCell();

                }
            }
        );

    Info.setItems(CInfo);

如果可能的话,我还需要能够通过在文本字段中拉出已设置的信息来通过单击新的联系人按钮来将新联系人添加到列表中。

0 个答案:

没有答案