User interface JavaFX";“快速修复”;带有工具提示和超链接
JavaFX是否提供类似的功能?这意味着你将鼠标悬停在一个坏了的东西上,并得到了一些解决方案,你可以立即应用。 我知道有工具提示,但它们只能包含文本,我需要一些可点击的东西。另一种解决方案类似于对话框,但我不想打开另一个窗口。我希望它出现在现阶段。 有什么建议吗 Edit:为了清楚起见,我想在基于JavaFX的应用程序上采用eclipse快速修复的概念,当鼠标悬停在圆形实例上时,可能会显示“快速修复”。我不想检查任何(java/javafx)源代码 Edit2:现在工具提示上有一个超链接:User interface JavaFX";“快速修复”;带有工具提示和超链接,user-interface,javafx,tooltip,User Interface,Javafx,Tooltip,JavaFX是否提供类似的功能?这意味着你将鼠标悬停在一个坏了的东西上,并得到了一些解决方案,你可以立即应用。 我知道有工具提示,但它们只能包含文本,我需要一些可点击的东西。另一种解决方案类似于对话框,但我不想打开另一个窗口。我希望它出现在现阶段。 有什么建议吗 Edit:为了清楚起见,我想在基于JavaFX的应用程序上采用eclipse快速修复的概念,当鼠标悬停在圆形实例上时,可能会显示“快速修复”。我不想检查任何(java/javafx)源代码 Edit2:现在工具提示上有一个超链接: HB
HBox box = new HBox();
Tooltip tooltip = new Tooltip();
tooltip.setText("Select an option:");
tooltip.setGraphic(new Hyperlink("Option 1"));
Tooltip.install(box, tooltip);
我现在有三个新问题:
提前谢谢 可以使用
setGraphic()
方法将任何节点添加到工具提示中。下面是一个简单的示例,演示如何使用工具提示实现“快速修复”功能:
import java.util.Random;
import javafx.application.Application;
import javafx.css.PseudoClass;
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TooltipWithQuickfix extends Application {
@Override
public void start(Stage primaryStage) {
TextField textField = new TextField();
textField.pseudoClassStateChanged(PseudoClass.getPseudoClass("invalid"), true);
textField.setTextFormatter(new TextFormatter<Integer>(c -> {
if (c.getText().matches("\\d*")) {
return c ;
}
return null ;
}));
textField.textProperty().isEmpty().addListener((obs, wasEmpty, isNowEmpty) ->
textField.pseudoClassStateChanged(PseudoClass.getPseudoClass("invalid"), isNowEmpty));
Tooltip quickFix = new Tooltip();
Hyperlink setToDefault = new Hyperlink("Set to default");
Hyperlink setToRandom = new Hyperlink("Set to random");
setToDefault.setOnAction(e -> {
textField.setText("42");
quickFix.hide();
});
Random rng = new Random();
setToRandom.setOnAction(e -> {
textField.setText(Integer.toString(rng.nextInt(100)));
quickFix.hide();
});
VBox quickFixContent = new VBox(new Label("Field cannot be empty"), setToDefault, setToRandom);
quickFixContent.setOnMouseExited(e -> quickFix.hide());
quickFix.setGraphic(quickFixContent);
textField.setOnMouseEntered(e -> {
if (textField.getText().isEmpty()) {
quickFix.show(textField, e.getScreenX(), e.getScreenY());
}
});
VBox root = new VBox(textField);
root.getStylesheets().add("style.css");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
可以使用
setGraphic()
方法将任何节点添加到工具提示中。下面是一个简单的示例,演示如何使用工具提示实现“快速修复”功能:
import java.util.Random;
import javafx.application.Application;
import javafx.css.PseudoClass;
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TooltipWithQuickfix extends Application {
@Override
public void start(Stage primaryStage) {
TextField textField = new TextField();
textField.pseudoClassStateChanged(PseudoClass.getPseudoClass("invalid"), true);
textField.setTextFormatter(new TextFormatter<Integer>(c -> {
if (c.getText().matches("\\d*")) {
return c ;
}
return null ;
}));
textField.textProperty().isEmpty().addListener((obs, wasEmpty, isNowEmpty) ->
textField.pseudoClassStateChanged(PseudoClass.getPseudoClass("invalid"), isNowEmpty));
Tooltip quickFix = new Tooltip();
Hyperlink setToDefault = new Hyperlink("Set to default");
Hyperlink setToRandom = new Hyperlink("Set to random");
setToDefault.setOnAction(e -> {
textField.setText("42");
quickFix.hide();
});
Random rng = new Random();
setToRandom.setOnAction(e -> {
textField.setText(Integer.toString(rng.nextInt(100)));
quickFix.hide();
});
VBox quickFixContent = new VBox(new Label("Field cannot be empty"), setToDefault, setToRandom);
quickFixContent.setOnMouseExited(e -> quickFix.hide());
quickFix.setGraphic(quickFixContent);
textField.setOnMouseEntered(e -> {
if (textField.getText().isEmpty()) {
quickFix.show(textField, e.getScreenX(), e.getScreenY());
}
});
VBox root = new VBox(textField);
root.getStylesheets().add("style.css");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
这个问题没有真正意义。JavaFX只是一个Java库,所以如果您使用JavaFX,Eclipse将为您的Java代码提供与其他Java代码相同的修复,这是有意义的。我说的是快速修复的概念,而不是修复java代码。例如,我正在显示一些数据,可能有一些错误,但我们需要人工交互来验证。我想通过“快速修复”来解决这个问题。哦,好的。(对我来说)这并不清楚。为什么不使用工具提示,并在其中放置超链接(或其他控件)?我对问题进行了编辑,以使其更清楚。我已经有了在工具提示中使用超链接的想法,但我无法实现它。你有什么例子吗?当你尝试的时候发生了什么?出了什么问题?发布一个为什么它不起作用的演示。这个问题没有真正的意义。JavaFX只是一个Java库,所以如果您使用JavaFX,Eclipse将为您的Java代码提供与其他Java代码相同的修复,这是有意义的。我说的是快速修复的概念,而不是修复java代码。例如,我正在显示一些数据,可能有一些错误,但我们需要人工交互来验证。我想通过“快速修复”来解决这个问题。哦,好的。(对我来说)这并不清楚。为什么不使用工具提示,并在其中放置超链接(或其他控件)?我对问题进行了编辑,以使其更清楚。我已经有了在工具提示中使用超链接的想法,但我无法实现它。你有什么例子吗?当你尝试的时候发生了什么?出了什么问题?发布一个为什么它不起作用的演示。