Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package de.javafxbuch;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.ListCell;
Expand Down Expand Up @@ -49,19 +47,8 @@ public void replaceText(int start, int end, String text) {
}
}

@Override
public void replaceSelection(String text) {
final int dot = getCaretPosition();
final int mark = getAnchor();
int start = Math.min(dot, mark);
int end = Math.max(dot, mark);
if (validate(createPreview(start, end, text))) {
super.replaceSelection(text);
}
}

private boolean validate(String text) {
if (text.matches("[-+]?[0-9]*\\.?[0-9]+") || text == "") {
if (text.matches("[-+]?[0-9]*\\.?[0-9]*") || text == "") {
System.out.println("ok");
return true;
}
Expand All @@ -84,18 +71,13 @@ private static class DoubleListCell extends ListCell<Double> {
DoubleTextField dtf = new DoubleTextField();

public DoubleListCell() {
dtf.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
commitEdit(Double.parseDouble(dtf.getText()));
}
});
dtf.setOnAction(e -> commitEdit(Double.parseDouble(dtf.getText())));
}

@Override
protected void updateItem(Double item, boolean empty) {
super.updateItem(item, empty);
if (item != null & !empty) {
if (item != null && !empty) {
dtf.setText(item.toString());
if (!isEditing()) {
setText(item.toString());
Expand Down