-
-
Save sedj601/41c6106bc9d304f787f0a2023b824af5 to your computer and use it in GitHub Desktop.
import java.util.Optional; | |
import javafx.application.Application; | |
import javafx.collections.FXCollections; | |
import javafx.collections.ObservableList; | |
import javafx.scene.Scene; | |
import javafx.scene.control.ListCell; | |
import javafx.scene.control.ListView; | |
import javafx.scene.control.TextInputDialog; | |
import javafx.scene.input.MouseEvent; | |
import javafx.scene.layout.VBox; | |
import javafx.stage.Stage; | |
/** | |
* | |
* @author blj0011 | |
*/ | |
public class App extends Application { | |
@Override | |
public void start(Stage primaryStage) { | |
primaryStage.setTitle("List View Sample"); | |
ObservableList<Person> people = FXCollections.observableArrayList(); | |
ListView<Person> listView = new ListView(people); | |
listView.setCellFactory((p) -> new ListCell<>() { | |
@Override | |
public void updateItem(Person person, boolean empty) { | |
super.updateItem(person, empty); | |
if (empty || person == null) { | |
setText(null); | |
} else { | |
setText(person.getName()); | |
} | |
} | |
}); | |
listView.setOnMouseClicked((MouseEvent click) -> { | |
if (click.getClickCount() == 2) { | |
//Use ListView's getSelected Item | |
Person tempPerson = listView.getSelectionModel().getSelectedItem(); | |
int index = listView.getSelectionModel().getSelectedIndex(); | |
TextInputDialog dialog = new TextInputDialog(tempPerson.getName()); | |
dialog.setTitle("Text Input Dialog"); | |
dialog.setHeaderText("Look, a Text Input Dialog"); | |
dialog.setContentText("Please enter your name:"); | |
// Traditional way to get the response value. | |
Optional<String> result = dialog.showAndWait(); | |
if (result.isPresent()) { | |
tempPerson.setName(result.get()); | |
listView.getItems().set(index, tempPerson); | |
} | |
} | |
}); | |
Person person1 = new Person("Tom"); | |
Person person2 = new Person("Kim"); | |
people.add(person1); | |
people.add(person2); | |
VBox root = new VBox(listView); | |
primaryStage.setScene(new Scene(root, 200, 250)); | |
primaryStage.show(); | |
} | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
Get out of your feelings and learn to listen. You literally are getting JavaFX advice from some of the best JavaFX people in the world. I am not included in that group. Yet, you have convinced yourself to go against their advice. It getting comical at this point.
You have no idea what I want to do and advise me not to do it. This is bullshit. You could delve into the topic before giving me advice without answering direct questions. I absolutely do not accept this style of communication.
I have enough experience to know how to respond to such answers.
Good luck coding. 😀
With pleasure. Without stupid answers.
OMG .. what a jerk - personally I'm certainly favoring any amateur (houseperson or not) eager to learn over a knows-it-all self proclaimed professional. At the end, the latter will also learn, most probably the hard way sitting on a jumble of brittle broken code.
As to this way around: also working for tableView, probably since fixing a bug in TableCell which prevented a cell update If the old row value was the same as the new.
Fuck. Why you tell me, what i need or what i'm not need.
I delete my question, good luck !