gpt4 book ai didi

java - 如何从下拉 ListView javafx 8中获取文本框中的点击项目?

转载 作者:行者123 更新时间:2023-12-02 05:42:55 29 4
gpt4 key购买 nike

我试图在文本框中获取点击值,我添加了监听器,但没有获取 adjact 输出。请建议我该怎么做。

ObservableList<String> data5 = FXCollections.observableArrayList(smooth);
listView.setItems(data5);

listView.getSelectionModel().selectedItemProperty().addListener(
new ChangeListener<String>() {
public void changed(ObservableValue<? extends String> ov,
String old_val, String new_val)
{
System.out.println("********"+new_val);

txtCustomerName.textProperty();
txtCustomerName.setText(new_val);
}
});

enter image description here

最佳答案

public class FillForm extends Application {

Text addressOne;
Text addressTwo;
Text mobileOne;
Text email;

@Override
public void start(Stage stage) throws Exception {

Label companyNameLbl = new Label("Company Name");
ComboBox<String> companyName = new ComboBox<String>();
companyName.setEditable(true);

populateCompanyName(companyName);
addComboListener(companyName);

HBox companyHbox = new HBox(25);
companyHbox.getChildren().addAll(companyNameLbl, companyName);

Label addressOneLbl = new Label("Address One");
addressOne = new Text();

HBox addressOneHbox = new HBox();
addressOneHbox.getChildren().addAll(addressOneLbl, addressOne);

Label addressTwoLbl = new Label("Address two");
addressTwo = new Text();

HBox addressTwoHbox = new HBox();
addressTwoHbox.getChildren().addAll(addressTwoLbl, addressTwo);

Label mobileLbl = new Label("Company Name");
mobileOne = new Text();

HBox mobileHbox = new HBox();
mobileHbox.getChildren().addAll(mobileLbl, mobileOne);

Label emailLbl = new Label("Company Name");
email = new Text();

HBox emailHbox = new HBox();
emailHbox.getChildren().addAll(emailLbl, email);

VBox form = new VBox(20);
form.getChildren().addAll(companyHbox, addressOneHbox, addressTwoHbox,
mobileHbox, emailHbox);

Scene scene = new Scene(form);
stage.setScene(scene);
scene.getStylesheets().add("/comboStyles.css");
stage.show();
}

private void addComboListener(final ComboBox<String> combo) {

combo.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent e) {
if (combo.getValue().equals("Apple")) {
addressOne.setText("\t Apple address one");
addressTwo.setText("\t Apple address two");
mobileOne.setText("\t Apple mobile number");
email.setText("\t Apple email");
}

}
});
}

public void populateCompanyName(ComboBox<String> combo) {
combo.getItems().add("Intel");
combo.getItems().add("Apple");
combo.getItems().add("Microsoft");
}

public static void main(String[] args) {
launch(args);
}
}

comboStyles.css

.combo-box .arrow, .combo-box .arrow-button{
-fx-background-color: transparent;
}

输出:

enter image description here

enter image description here

我做了一个粗略的例子,没有使用正确的布局。您可以为您的 UI 使用适当的布局。使用 data5 列表填充组合框,并在组合框的操作监听器中检查所选值并填写其他字段。

更新

由于您必须按照贵公司的规定仅使用文本框,因此以下链接将指导您。您必须通过扩展 Javafx 的 Text 类来创建自定义文本框。

https://github.com/privatejava/javafx-autocomplete-field

http://blog.ngopal.com.np/2011/07/04/autofill-textbox-with-filtermode-in-javafx-2-0-custom-control/

自动填充文本字段 jar :

https://code.google.com/p/jfx-autocomplete-textfield/

关于java - 如何从下拉 ListView javafx 8中获取文本框中的点击项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24362525/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com