以下代码有效,但是当我从“男性”更改为“女性”时,反之亦然,cbSpouse会加载新的项目。正确的数据被加载。但是问题是,如果我单击cbSpouse中的向下箭头,则需要等待几分钟,然后才能看到下拉菜单。没有数据库交互,所有必需的数据已经位于“可观察”列表中。
ObservableList<String> GenderOptions = FXCollections.observableArrayList("Male", "Female");
cbGender.getItems().clear();
cbGender.setItems(GenderOptions);
cbGender.setVisibleRowCount(GenderOptions.size());
cbGender.getSelectionModel().selectFirst();
cbGender.valueProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue ov, String t, String t1) {
System.out.println("Change Listener for cbGender - oldValue "+t+" new value"+t1);
if ((t1.equals("Male")) || (t.equals(null))) {
cbSpouse.setItems(myMainApp.getFemaleSpouses());
if (thisPerson.getPhoto() == null) {
thePicture.setImage(defaultMale);
}
} else {
cbSpouse.setItems(myMainApp.getMaleSpouses());
if (thisPerson.getPhoto() == null) {
thePicture.setImage(defaultFemale);
}
}
cbSpouse.getSelectionModel().selectFirst();
}
});
//
myMainApp.getMaleSpouses()中大约有300项实际上返回了Observable列表。
有人可以帮我吗?
谢谢。
Hornigold
答案 0 :(得分:-1)
这是较小的版本,效果很好。只需不断更改性别并单击“配偶”,就会出现新列表。
package application;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.control.Tooltip;
import javafx.scene.text.Text;
/**
*
* @author Hornigold Arthur
*/
public class APerson {
private final StringProperty firstName;
private final StringProperty lastName;
private final StringProperty gender;
private final IntegerProperty familyID;
private final IntegerProperty personID;
private final StringProperty toolTipText;
private final Tooltip toolTip;
public APerson() {
this(null, null, null, 0, 0 );
}
/**
* Constructor with some initial data.
*
* @param familyID
* @param personID
* @param firstName
* @param lastName
* @param gender
*/
public APerson( String firstName, String lastName, String gender, int familyID, int personID) {
this.firstName = new SimpleStringProperty(firstName);
this.lastName = new SimpleStringProperty(lastName);
this.gender = new SimpleStringProperty(gender);
this.familyID = new SimpleIntegerProperty(familyID);
this.personID = new SimpleIntegerProperty(personID);
this.toolTipText = new SimpleStringProperty(null);
this.toolTip = new Tooltip();
}
//
public int getFamilyID() {
return familyID.get();
}
public void setFamilyID(int FamilyID) {
this.familyID.set(FamilyID);
}
public IntegerProperty familyIDProperty() {
return familyID;
}
//
public int getPersonID() {
return personID.get();
}
public void setPersonID(int PersonID) {
this.personID.set(PersonID);
}
public IntegerProperty personIDProperty() {
return personID;
}
//
public String getFirstName() {
return firstName.get().trim();
}
public void setFirstName(String FirstName) {
this.firstName.set(FirstName);
}
public StringProperty firstNameProperty() {
return firstName;
}
//
public String getLastName() {
return lastName.get();
}
public void setLastName(String LastName) {
this.lastName.set(LastName);
}
public StringProperty lastNameProperty() {
return lastName;
}
public String getGender() {
return gender.get();
}
public void setGender(String Gender) {
this.gender.set(Gender);
}
public StringProperty genderProperty() {
return gender;
}
public String LoadToolTipText() {
String tmp = "";
String headerLine = "<body style=\"background-color: LavenderBlush; border-style: none;\"> <u><b><font color=\"red\">Click Mouse's right button to see options</font></b></u><br><br>";
headerLine = headerLine+"<font color=\"red\">Use ARROW keys to scrol the Tooltip</font></b></u><br><br>";
Text t1 = new Text();
t1.setText(headerLine);
String ToolTipText = t1.getText() + this.toString() + "<br>";
ToolTipText = ToolTipText + "<br></body>";
this.toolTip.setStyle("-fx-background-color: pink; -fx-text-fill: black; -fx-font: normal normal 12pt \"Times New Roman\"");
this.toolTip.setText(ToolTipText);
// System.out.println("Tip: "+ToolTipText);
return ToolTipText;
}
public Tooltip getToolTip() {
// A browser.
return toolTip;
}
//
public String toString() {
String tmp = this.getFirstName() + " " + this.getLastName() + " [" + this.getPersonID()+"] ";
return tmp;
}
}
Main.java
package application;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
test000Controller myController;
static private javafx.collections.ObservableList<APerson> persons = javafx.collections.FXCollections.observableArrayList();
static private javafx.collections.ObservableList<APerson> fathers = javafx.collections.FXCollections.observableArrayList();
static private javafx.collections.ObservableList<APerson> mothers = javafx.collections.FXCollections.observableArrayList();
@Override
public void start(Stage stage) throws Exception {
loadFathers();
FXMLLoader loader = new FXMLLoader(getClass().getResource("test000.fxml"));
Parent root = (Parent) loader.load();
myController = loader.getController();
Scene scene = new Scene(root);
myController.persons = persons;
myController.fathers = fathers;
myController.mothers = mothers;
myController.setCBValues();
stage.setTitle("Check editable Combo - TEST000");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
private void loadFathers() {
persons.clear();
persons.add(new APerson("*** Not ", "Known ***","F" ,2,0));
persons.add(new APerson("Nesammal", "Rivington","F" ,2,57));
persons.add(new APerson("Ratnammal","Andews","F",1,55));
persons.add(new APerson("Hornigold","Arthur","M", 1,63));
persons.add(new APerson("Andrews","Sundareson","M", 2,60));
persons.add(new APerson("Christopher","Easweradoss","M", 3,57));
persons.add(new APerson("Arthur","Kennedy","M", 4,55));
persons.add(new APerson("Victoria","Arthur","F" , 1,95));
persons.add(new APerson("Eliza", "Daniel","F", 1,60));
fathers.clear();
fathers.add(new APerson("*** Not ", "Known ***","F" ,2,0));
fathers.add(new APerson("Hornigold","Arthur","M", 1,63));
fathers.add(new APerson("Andrews","Sundareson","M", 2,60));
fathers.add(new APerson("Christopher","Easweradoss","M", 3,57));
fathers.add(new APerson("Arthur","Kennedy","M", 4,55));
mothers.clear();
mothers.add(new APerson("*** Not ", "Known ***","F" ,2,0));
mothers.add(new APerson("Nesammal", "Rivington","F" ,2,57));
mothers.add(new APerson("Ratnammal","Andews","F",1,55));
mothers.add(new APerson("Victoria","Arthur","F" , 1,95));
mothers.add(new APerson("Eliza", "Daniel","F", 1,60));
}
}
test000.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="502.0" prefWidth="325.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.test000Controller">
<children>
<VBox prefHeight="431.0" prefWidth="301.0" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="10.0">
<children>
<Label text="Fathers : ">
<font>
<Font name="Times New Roman Bold" size="12.0" />
</font>
</Label>
<ComboBox fx:id="cbFather" editable="true" onAction="#onCBFather" prefHeight="35.0" prefWidth="325.0" promptText="Enter search string" stylesheets="@application.css">
<VBox.margin>
<Insets top="5.0" />
</VBox.margin></ComboBox>
<TextField fx:id="txtValue" editable="false" prefHeight="38.0" prefWidth="301.0" promptText="Selected value" style="-fx-background-color: white; -fx-border-color: red;">
<VBox.margin>
<Insets top="15.0" />
</VBox.margin>
</TextField>
<Label text="Mothers : ">
<font>
<Font name="Times New Roman Bold" size="12.0" />
</font>
<VBox.margin>
<Insets top="5.0" />
</VBox.margin>
</Label>
<ComboBox fx:id="cbMother" editable="true" onAction="#onCBMother" prefHeight="35.0" prefWidth="325.0" promptText="Enter search string" stylesheets="@application.css">
<VBox.margin>
<Insets top="5.0" />
</VBox.margin>
</ComboBox>
<Label text="Spouses : ">
<font>
<Font name="Times New Roman Bold" size="12.0" />
</font>
<VBox.margin>
<Insets top="5.0" />
</VBox.margin>
</Label>
<ComboBox fx:id="cbSpouse" editable="true" prefHeight="35.0" prefWidth="325.0" promptText="Enter search string" stylesheets="@application.css">
<VBox.margin>
<Insets top="5.0" />
</VBox.margin>
</ComboBox>
<Label text="Gender:">
<font>
<Font name="Times New Roman Bold" size="12.0" />
</font>
<VBox.margin>
<Insets top="5.0" />
</VBox.margin>
</Label>
<ComboBox fx:id="cbGender" editable="true" onAction="#onCBGender" onMouseClicked="#handleGenderMoouseEvent" prefHeight="35.0" prefWidth="325.0" promptText="Select Gender" stylesheets="@application.css">
<VBox.margin>
<Insets top="5.0" />
</VBox.margin>
</ComboBox>
</children>
</VBox>
<HBox layoutX="14.0" layoutY="450.0" prefHeight="38.0" prefWidth="294.0">
<children>
<Button fx:id="btnCB1" mnemonicParsing="false" onAction="#showCB1Value" prefHeight="41.0" prefWidth="123.0" text="CB1 value">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Button>
<Button fx:id="btnCB2" mnemonicParsing="false" onAction="#showCB2Value" prefHeight="41.0" prefWidth="123.0" text="CB2 value">
<font>
<Font name="System Bold" size="14.0" />
</font>
<HBox.margin>
<Insets left="25.0" />
</HBox.margin>
</Button>
</children>
</HBox>
</children>
</AnchorPane>
test000Controller.java
package application;
import application.APerson;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.input.InputMethodEvent;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.util.Callback;
import javafx.util.StringConverter;
public class test000Controller {
boolean searchWordStartOnly = true;
private ObservableList<APerson> originalData;
private ObservableList<APerson> originalData2;
public javafx.collections.ObservableList<APerson> persons;
public javafx.collections.ObservableList<APerson> fathers;
public javafx.collections.ObservableList<APerson> mothers;
@FXML
private ResourceBundle resources;
@FXML
private URL location;
@FXML
private ComboBox<APerson> cbFather;
@FXML
private ComboBox<APerson> cbMother;
@FXML
private ComboBox<APerson> cbSpouse;
@FXML
private ComboBox<String> cbGender;
@FXML
private TextField txtValue;
@FXML
private Button btnCB1;
@FXML
private Button btnCB2;
@FXML
void onCBFather(ActionEvent event) {
if (event.getEventType().toString() != null) {
System.out.println("ActionEvent - CBFather - Fired = "+event.getEventType().toString());
}
}
@FXML
void onCBMother(ActionEvent event) {
if (event.getEventType().toString() != null) {
System.out.println("ActionEvent - CBMother - Fired = "+event.getEventType().toString());
}
}
@FXML
void showCB1Value(ActionEvent event) {
txtValue.setText("Button 1 was clicked - "+cbFather.getValue());
}
@FXML
void showCB2Value(ActionEvent event) {
txtValue.setText("Button 2 was clicked - "+cbMother.getValue());
}
@FXML
void onCBGender(ActionEvent event) {
// event.fireEvent(arg0, arg1);
cbGender.getSelectionModel().selectedItemProperty().addListener((options, oldValue, newValue) -> {
System.out.println("cbGender newValue -> " + newValue);
});
}
@FXML
void handleGenderMoouseEvent(MouseEvent event) {
System.out.println("This is MOUSE CLICKED on cbGENDER");
}
@FXML
void initialize() {
assert cbFather != null : "fx:id=\"cbFather\" was not injected: check your FXML file 'test000.fxml'.";
assert txtValue != null : "fx:id=\"txtValue\" was not injected: check your FXML file 'test000.fxml'.";
assert cbMother != null : "fx:id=\"cbMother\" was not injected: check your FXML file 'test000.fxml'.";
assert cbSpouse != null : "fx:id=\"cbSpouse\" was not injected: check your FXML file 'test000.fxml'.";
assert btnCB1 != null : "fx:id=\"btnCB1\" was not injected: check your FXML file 'test000.fxml'.";
assert btnCB2 != null : "fx:id=\"btnCB2\" was not injected: check your FXML file 'test000.fxml'.";
assert cbGender != null : "fx:id=\"cbGender\" was not injected: check your FXML file 'test000.fxml'.";
}
public void setCBValues() {
cbGender.valueProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue ov, String t, String t1) {
System.out.println("Change Listener for cbGender - oldValue "+t+" new value"+t1);
if ((t1.equals("Male")) || (t.equals(null))) {
cbSpouse.setItems(mothers);
} else {
cbSpouse.setItems(fathers);
}
cbSpouse.getSelectionModel().selectFirst();
}
});
//
ObservableList<String> GenderOptions = FXCollections.observableArrayList("Male", "Female");
cbGender.setItems(GenderOptions);
cbGender.setValue("Male");
createCBFather(persons);
createCBMother(persons);
}
public void createCBFather(javafx.collections.ObservableList<APerson> persons) {
cbFather.getItems().clear();
cbFather.setItems(persons);
cbFather.setEditable(true);
cbFather.setMaxWidth(Double.MAX_VALUE);
cbFather.setVisibleRowCount(5);
originalData = cbFather.getItems();
cbFather.getEditor().setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (cbFather.getEditor().getText() == null) {
cbFather.getItems().clear();
cbFather.setItems(persons);
cbFather.setEditable(true);
cbFather.setMaxWidth(Double.MAX_VALUE);
cbFather.setVisibleRowCount(5);
}
System.out.println("MOUSE PRESSED!!! in EDITOR");
}
});
//
cbFather.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (cbFather.getEditor().getText() == null) {
cbFather.getItems().clear();
cbFather.setItems(persons);
cbFather.setEditable(true);
cbFather.setMaxWidth(Double.MAX_VALUE);
cbFather.setVisibleRowCount(5);
}
System.out.println("MOUSE PRESSED!!! in CB BUTTON");
}
});
//
cbFather.getSelectionModel().selectFirst();
//
cbFather.setConverter(new CBFatherConverter());
//
setCellFactory(cbFather);
//
handleKeyPressed(cbFather, originalData);
cbFather.valueProperty().addListener(new ChangeListener<APerson>() {
@Override
public void changed(ObservableValue ov, APerson t, APerson t1) {
System.out.println("Change Listener for cbFather - ov "+t+" new value"+t1);
if (t1 == null) {
cbFather.setItems(persons);
// cbFather.getSelectionModel().selectFirst();;
}
}
});
}
class CBFatherConverter extends StringConverter<APerson> {
@Override
public String toString(APerson object) {
if (object == null) {
cbFather.setPromptText("Use Arrow Keys or type to locate entry");
return null;
}
return object.toString();
}
@Override
public APerson fromString(String thisString) {
// TODO Auto-generated method stub
for (APerson pers : cbFather.getItems()) {
if (pers.toString().equals(thisString)) {
APerson person = pers;
return person;
}
}
return null;
}
}
//
public void createCBMother(javafx.collections.ObservableList<APerson> persons) {
cbMother.setItems(persons);
cbMother.setEditable(true);
cbMother.setMaxWidth(Double.MAX_VALUE);
cbMother.setVisibleRowCount(5);
originalData2 = cbMother.getItems();
cbMother.getSelectionModel().selectFirst();
// if (cbGender.getValue().equals("Male")) {
// cbSpouse.setItems(mothers);
// } else {
// cbSpouse.setItems(fathers);
// }
//
cbMother.setConverter(new CBMotherConverter());
//
setCellFactory(cbMother);
//
handleKeyPressed(cbMother, originalData2);
// cbMother.valueProperty().addListener(new ChangeListener<APerson>() {
// @Override
// public void changed(ObservableValue ov, APerson t, APerson t1) {
// System.out.println("Change Listener for cbMother - ov "+t+" new value"+t1);
// }
// });
//
// cbGender.setValue("Male");
//
}
//
class CBMotherConverter extends StringConverter<APerson> {
@Override
public String toString(APerson object) {
if (object == null) {
cbMother.setPromptText("Use Arrorw Keys or type to locate entry");
return null;
}
return object.toString();
}
@Override
public APerson fromString(String thisString) {
// TODO Auto-generated method stub
for (APerson pers : cbMother.getItems()) {
if (pers.toString().equals(thisString)) {
APerson person = pers;
return person;
}
}
return null;
}
}
//
public void setCellFactory(ComboBox<APerson> thisCombo) {
thisCombo.setCellFactory(new Callback<ListView<APerson>, ListCell<APerson>>() {
@Override
public ListCell<APerson> call(ListView<APerson> param) {
final ListCell<APerson> cell = new ListCell<APerson>() {
@Override
protected void updateItem(APerson item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
final ListCell<APerson> this$ = this;
item.LoadToolTipText();
String htmlString = item.getToolTip().getText();
Tooltip.install(this$, createToolTip(htmlString));
String str = item.toString();
setText(str);
if (item.getGender() == "M") {
String cellStyle = " -fx-font-size: 16;\n"
+ " -fx-font-family: \"Times New Roman\";\n" + "-fx-text-fill: blue;";
setStyle(cellStyle);
} else {
String cellStyle = " -fx-font-size: 16;\n"
+ " -fx-font-family: \"Times New Roman\";\n" + "-fx-text-fill: red;";
setStyle(cellStyle);
}
}
}
}; // ListCell
return cell;
}
}); // setCellFactory
}
public void handleKeyPressed(ComboBox<APerson> thisCombo, ObservableList<APerson> originalData) {
thisCombo.addEventHandler(KeyEvent.KEY_PRESSED, t -> thisCombo.hide());
thisCombo.addEventFilter(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {
private boolean moveCaretToPos = false;
private int caretPos;
@Override
public void handle(KeyEvent event) {
switch (event.getCode()) {
case UP:
if (thisCombo.getEditor().equals(null)) {
thisCombo.getSelectionModel().selectFirst();
thisCombo.show();
}
break;
//
case DOWN:
System.out.println("Processing DOWN arrow");
if (thisCombo.getEditor().equals(null)) {
System.out.println("Editor is NULL");
thisCombo.getSelectionModel().selectFirst();
thisCombo.show();
}
if (!thisCombo.isShowing()) {
if (thisCombo.getItems().size() == 0) {
System.out.println("Processing DOWN arrow - Combo Box is EMPTY");
thisCombo.setItems(originalData);
} else {
System.out.println("Processing DOWN arrow - Has items.");
}
thisCombo.getSelectionModel().selectFirst();
thisCombo.show();
}
break;
//
case BACK_SPACE:
moveCaretToPos = true;
caretPos = thisCombo.getEditor().getCaretPosition();
break;
//
case DELETE:
moveCaretToPos = true;
caretPos = thisCombo.getEditor().getCaretPosition();
break;
case ENTER:
break;
//
case RIGHT:
case LEFT:
case SHIFT:
case HOME:
case END:
case TAB:
case CONTROL:
return;
default:
if (event.getCode().ALPHANUMERIC != null) {
// System.out.println("in ALPHANUMERIC input");
locateItems();
}
break;
}
APerson waste = (APerson) getComboBoxValue(thisCombo);
if (waste != null) {
txtValue.setText(waste.getFirstName()+" ID = "+waste.getPersonID());
} else {
txtValue.setText("");
}
}
private void locateItems() {
txtValue.setText("Alpha numeric input");
ObservableList<APerson> list = FXCollections.observableArrayList();
int selectedIndex = 0;
for (APerson aData : originalData) {
String tmp = thisCombo.getEditor().getText().toLowerCase();
if (checkMatch(thisCombo, aData, tmp)) {
list.add(aData);
selectedIndex++;
}
}
String t = thisCombo.getEditor().getText();
thisCombo.setItems(list);
thisCombo.getEditor().setText(t);
if (!moveCaretToPos) {
caretPos = -1;
}
moveCaret(t.length());
if (!list.isEmpty()) {
thisCombo.hide();
if (list.size() > 5) {
thisCombo.setVisibleRowCount(5);
} else {
thisCombo.setVisibleRowCount(list.size());
}
thisCombo.getSelectionModel().select(selectedIndex);
thisCombo.show();
}
}
private void moveCaret(int textLength) {
if (caretPos == -1) {
thisCombo.getEditor().positionCaret(textLength);
} else {
thisCombo.getEditor().positionCaret(caretPos);
}
moveCaretToPos = false;
}
});
}
private boolean checkMatch(ComboBox thisCombo, APerson aData, String tmp) {
boolean retValue = false;
if (aData != null && thisCombo.getEditor().getText() != null) {
String[] words = aData.toString().split(" ");
for (String thisWord : words) {
if (searchWordStartOnly) {
if (thisWord.toLowerCase().startsWith(tmp)) {
return true;
}
} else {
if (thisWord.toLowerCase().contains(tmp)) {
return true;
}
}
}
}
return retValue;
}
public Object getComboBoxValue(ComboBox thisCombo) {
System.out.println("getComboBoxValue - name = "+thisCombo.getSelectionModel().getSelectedItem());
if (thisCombo.getSelectionModel().getSelectedIndex() < 0) {
return null;
} else {
System.out.println("Item Selected in cbFather is = "+thisCombo.getSelectionModel().getSelectedItem());
return thisCombo.getSelectionModel().getSelectedItem();
}
}
//
private Tooltip createToolTip(String htmlStr) {
Tooltip thisToolTip = new Tooltip();
WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
webEngine.loadContent(htmlStr);
thisToolTip.setStyle("\n" + " -fx-border-color: black;\n" + " -fx-border-width: 1px;\n"
+ " -fx-font: normal bold 12pt \"Times New Roman\" ;\n"
+ " -fx-background-color: LavenderBlush;\n" + " -fx-text-fill: black;\n"
+ " -fx-background-radius: 4;\n" + " -fx-border-radius: 4;\n" + " -fx-opacity: 1.0;");
thisToolTip.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
thisToolTip.setGraphic(browser);
thisToolTip.setAutoHide(false);
thisToolTip.setMaxWidth(300);
thisToolTip.setPrefHeight(400);
thisToolTip.setGraphicTextGap(0.0);
return thisToolTip;
}
}
在此示例中,数据是经过硬编码的,并且在Main.java中,但是在其他版本中,数据是从 静态私有javafx.collections.ObservableList父亲= javafx.collections.FXCollections.observableArrayList(); 静态私有javafx.collections.ObservableList Mothers = javafx.collections.FXCollections.observableArrayList();
在更改cbGender valueProperty之前,更早地从数据库加载ObservableList。
谢谢