我最近开始了一个JavaFX项目,我想使用Maven作为我的编译器/部署工具.
是否有一个很好的教程或插件来集成JavaFX和Maven?
由于我使用的是JavaFX 8,所以我textarea的所有内容都不适用transparency于相应的css中定义的内容.它在Java 7中运行良好,但对于JavaFX 8的候选版本,我不能像以前那样表现.
编辑:这个问题是关于JavaFX TextArea,而不是JTextArea.
-fx-background-color: rgba(53,89,119,0.2);对textarea没有任何影响,虽然它应该有一个0.2的alpha值,但它是不相干的......
这是一个已知问题吗?
我随机地以高频率接收数据对象,并且需要使用这些来更新JavaFX GUI.但是,我不想用大量的runnable填充javafx事件队列(我使用Platform.RunLater).
我一直在考虑如何最好地实现限制算法.
有关如何以简短有效的方式为JavaFX Platform.RunLater GUI更新设计限制算法的任何建议?
给定一个场景的控制器调用业务代码引发异常.我怎样才能以一般方式处理这类例外?
我尝试了这个Thread.setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler)方法,但是没有调用它,所以我相信异常会在JavaFX框架内的某个地方被捕获.
我该怎么做才能处理此异常或至少向用户显示一些有用的信息?
我创建了一个报告并将其导出为文本文件,以便在矩阵打印机中打印,但是,作业的结果是一个空白页面.我在ubuntu中做了同样的事情并且打印正确.这是一个Java bug吗?
这是我向您展示问题的示例代码:
public class PrintError extends Application {
public static void main(String args[]) {
launch(args);
}
public void start(Stage stage) throws PrintException {
PrinterJob printerJob = PrinterJob.createPrinterJob();
printerJob.showPrintDialog(stage);
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(new Copies(printerJob.getJobSettings().getCopies()));
printRequestAttributeSet.add(new JobName("test", Locale.getDefault()));
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc mydoc = new SimpleDoc(ClassLoader.class.getResourceAsStream("/should-be-printed.txt"), flavor, null);
DocPrintJob job = getPrintService(printerJob.getPrinter().getName()).createPrintJob();
job.print(mydoc, printRequestAttributeSet);
}
private PrintService getPrintService(String name) {
for (PrintService printService : java.awt.print.PrinterJob.lookupPrintServices()) {
if (name.equalsIgnoreCase(printService.getName())) {
return printService;
}
}
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
此示例在JavaFx …
我需要在窗格上有一个选择侦听器和select方法,以便能够在单击节点时监视并显示突出显示.
我做了以下事情:
public class PaneWithSelectionListener extends Pane {
private ObjectProperty<Annotation> selectedAnnotation = new SimpleObjectProperty<>();
public PaneWithSelectionListener() {
super();
selectedAnnotation.addListener((obs, oldAnno, newAnno) -> {
if (oldAnno != null) {
oldAnno.setStyle("");
}
if (newAnno != null) {
newAnno.setStyle("-fx-border-color: blue;-fx-border-insets: 5;-fx-border-width: 1;-fx-border-style: dashed;");
}
});
setOnMouseClicked(e->selectAnnotation(null));
}
public void selectAnnotation(Annotation ann){
selectedAnnotation.set(ann);
}
}
Run Code Online (Sandbox Code Playgroud)
这很有效 - 但是我不能再使用SceneBuilder了,因为我的FXML引用了这个PaneWithSelectionListener而不是Pane.我不确定如何将自定义窗格导入SceneBuilder.我已经看了其他问题,它们都是FXML和控制器的组合 - 这只是一个Pane.
有没有人知道这样做的方法,或者可能在初始化时交换Panea PaneWithSelectionListener?
谢谢
我正在尝试解决jdk中的这个错误:http://bugs.java.com/bugdatabase/view_bug.do? video_id = 8088624
public class Blubb extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Button btn = new Button("Click");
btn.setTooltip(new Tooltip("Blubb"));
Scene scene = new Scene(new BorderPane(btn), 320, 240);
primaryStage.setScene(scene);
primaryStage.show();
Stage secondStage = new Stage();
secondStage.setScene(new Scene(new BorderPane(new Button("Click")), 320, 240));
//secondStage.initOwner(primaryStage);
secondStage.show();
}
}
Run Code Online (Sandbox Code Playgroud)
如果主舞台上的按钮悬停,它将出现在第二阶段的前面.我发现调用initOwner()一个舞台将消除这种行为.
现在我的问题是:我有多个"弹出窗口",它们有一个共同的所有者(主要阶段).将鼠标悬停在主阶段上的控件上后,在initOwner()解决方法后不会导致任何意外行为.然而,如果您将鼠标悬停在弹出窗口中的控件上而另一个弹出窗口处于焦点位置,则悬停的弹出窗口将会隐藏焦点.
有没有办法可以解决这个错误,不仅是初级阶段,还有弹出窗口?
更新:结果我的解决方法有不良副作用.舞台状态的Javadocs如下:
舞台将始终位于其父窗口的顶部.
另外,什么是一种解决方法,使弹出窗口不"总是在顶部"和最小化?
我想要实现的实际上是浏览器的取消按钮,但使用JavaFX的webview.这是我到目前为止的代码:
Worker<Void> loadWorker = webView.getEngine().getLoadWorker();
if (loadWorker != null) {
Platform.runLater(() -> loadWorker.cancel());
}
Run Code Online (Sandbox Code Playgroud)
但它有时会起作用,有时却不起作用.
取消加载页面的webview/webengine任务的正确方法是什么?
我有一个带有几个UI元素的自定义对话框。一些TextField用于数字输入。当按下逃逸键并且焦点位于任何数字文本字段上时,此对话框不会关闭。当焦点位于没有此自定义TextFormatter的其他TextField上时,该对话框可以正常关闭。
这是简化的代码:
package application;
import java.text.DecimalFormat;
import java.text.ParsePosition;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
TextField name = new TextField();
HBox hb1 = new HBox();
hb1.getChildren().addAll(new Label("Name: "), name);
TextField id = new TextField();
id.setTextFormatter(getNumberFormatter()); // numbers only
HBox hb2 = new HBox();
hb2.getChildren().addAll(new Label("ID: "), id);
VBox vbox = new …Run Code Online (Sandbox Code Playgroud) 我正在尝试让一个可以在我的机器上完美运行的应用程序在docker上运行,这是我的docker文件:
FROM openjdk:11-jre-slim
VOLUME /tmp
ADD someJar.jar someJar.jar
ADD lib lib
ADD config.properties config.properties
ENTRYPOINT ["java", "-javaagent:lib/aspectjweaver-1.9.2.jar",
"-javaagent:lib/spring-instrument-5.1.6.RELEASE.jar", "--module-path",
"lib/javafx-sdk-11.0.2", "--add-modules=javafx.controls", "-
Dprism.verbose=true", "-jar","someJar.jar"]
Run Code Online (Sandbox Code Playgroud)
我还尝试将其基于高山openjdk11版本,其结果相同:
FROM adoptopenjdk/openjdk11:alpine
VOLUME /tmp
RUN apk update && apk add libx11 mesa-gl gtk+3.0 && apk update
ADD someJar.jar someJar.jar
ADD lib lib
ADD config.properties config.properties
ENTRYPOINT ["java", "-javaagent:lib/aspectjweaver-1.9.2.jar", "-javaagent:lib/spring-instrument-5.1.6.RELEASE.jar", "--module-path", "lib", "--add-modules=javafx.controls", "-Dprism.verbose=true", "-jar","someJar.jar"]
Run Code Online (Sandbox Code Playgroud)
The lib folder contains the linux flavor of the openJFX runtime (.so files and .jar files). I am developing this on …