标签: javafx-8

JavaFX 等待页面加载后再继续

我有一个方法为 WebView 的 WebEngine 设置一个新网页,该网页需要等到页面加载完成才能继续当前方法。

本质上我想要:

MyMethod()
{
    navigateToNewUrl();
    waitForPageToLoad(); // This is the part I am struggling with
    doSomethingElse();
}
Run Code Online (Sandbox Code Playgroud)

我尝试过使用 ChangeListener() 但它只会在我的方法完成执行后执行。我在谷歌上搜索了许多导致更多挫败感的术语,例如“java非阻塞等待布尔值”。最终我做到了启动新线程(以防止应用程序 GUI 锁定)并使用 CountDownTimer (而不是 Thread.join() )。下面的代码是我无数次尝试获得我想要的东西。

public static Boolean pageLoaded;
public volatile static CountDownLatch latch;

private static void TestMethod()
{
    // Set the CountDownLatch
    latch = new CountDownLatch(1);

    // Set the page loaded flag
    pageLoaded = false;

    // Navigate to new window
    myWebView.getEngine().load("https://www.google.com/");

    // Call a method, that starts a thread, that checks if the page …
Run Code Online (Sandbox Code Playgroud)

multithreading javafx-8

1
推荐指数
1
解决办法
6506
查看次数

在 JavaFx 中格式化表视图中的最后一行

我需要通过 CSS 格式化 JavaFX 中表格视图的最后一行,如果在 CSS 中不可能,那么如何在代码中做到这一点。

css java fxml javafx-8

1
推荐指数
1
解决办法
2163
查看次数

Java FX ComboBoxTableCell 在每个单元格中显示

我有一个表,其中有一个组合单元格,您可以从中为每个行条目选择一个值。问题是,下拉列表仅在编辑单元格时显示,我希望它始终显示在每一行上。这可能吗?如果可能的话,如何实现?

在此输入图像描述

    TableColumn<Product, String> actionsCol = new TableColumn<Product, String>("Exception Reason");
    actionsCol.setCellValueFactory(new PropertyValueFactory("exceptionReason"));
    actionsCol.setCellFactory(ComboBoxTableCell.forTableColumn(exceptionReasons));
    actionsCol.setOnEditCommit(
            new EventHandler<CellEditEvent<Product, String>>() {
                @Override
                public void handle(CellEditEvent<Product, String> t) {
                    ((Product) t.getTableView().getItems().get(t.getTablePosition().getRow())).setExceptionReason(t.getNewValue());
                };
    });
    actionsCol.setEditable(true);
Run Code Online (Sandbox Code Playgroud)

javafx javafx-8

1
推荐指数
1
解决办法
2864
查看次数

如何推断 TextFlow 中的分页符?

我正在尝试在我的应用程序中创建一个记事本屏幕。创建注释后,它们将被锁定且无法编辑,但是可以将新页面添加到注释中。

我认为使用 TextFlow 可以很好地控制这一点。我想做的是:

**Note Taker Name**
**Date of Note**
Line of Note Text
Line of Note Text
Line of Note Text
Line of Note Text
------------------------------------------
**Note Taker Name**
**Date of Note**
Line of Note Text
Line of Note Text
Line of Note Text
Line of Note Text
Run Code Online (Sandbox Code Playgroud)

我已经尝试过这种方式:

String s1 = "line of text";

textFlow.getChildren().add(new Text(s1));
textFlow.getChildren().add(new Text(System.lineSeparator()));
textFlow.getChildren().add(new Separator(Orientation.HORIZONTAL));
textFlow.getChildren().add(new Text(System.lineSeparator()));
textFlow.getChildren().add(new Text(s1));

scrollPane.setFitToWidth(true);
Run Code Online (Sandbox Code Playgroud)

这几乎为我提供了我想要的东西,除了分隔符只是一条细线。我希望该线穿过整个 TextFlow,但我不太确定如何去做。

谢谢。

textflow javafx-8

1
推荐指数
1
解决办法
1973
查看次数

在 javaFX 8 中添加 Button 节点会引发异常 - javafx.fxml.LoadException:无效标识符

我在创建的 StackPane 布局中添加了两个图像视图,但是当我尝试在 StackPane 布局中添加按钮节点时,虽然图像工作得很好,但按钮不允许程序运行并抛出此错误我无法弄清楚的例外:

> > Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException: Invalid identifier.
/C:/Users/Steli/Dropbox/Java_Projects/IntelliJ%20IDEA%20Projects/DokkanCardsPreview/out/production/DokkanCardsPreview/fxml/home.fxml:33
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:901)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at …
Run Code Online (Sandbox Code Playgroud)

java exception intellij-idea fxml javafx-8

1
推荐指数
1
解决办法
1157
查看次数

字符串变量到 stringProperty 的转换

我正在使用javafx。
我必须将 Object 类型的变量转换为 StringProperty 类型。

Object v = "var";
StringProperty var = (StringProperty) v;
Run Code Online (Sandbox Code Playgroud)

我没有收到任何编译时错误。但java.lang.ClassCastException出现了。
谢谢

java javafx-8

1
推荐指数
1
解决办法
8999
查看次数

如何列出JavaFX中的所有颜色

我想列出班上所有的颜色Color.<color>

在哪里可以找到列出的所有颜色?

javafx javafx-2 javafx-8

0
推荐指数
1
解决办法
1710
查看次数

禁用TabPane中的默认动画

我想在创建新标签时禁用默认动画。

Tab tabA = new Tab();
      tabA.setText("Tab A");
      tabPane.getTabs().add(tabA);
Run Code Online (Sandbox Code Playgroud)

这可能吗?

javafx javafx-2 javafx-8

0
推荐指数
1
解决办法
1290
查看次数

JavaFX 8 WebEngine打印方法无法在横向打印

我正在尝试在横向A4纸上的JavaFX WebView(JavaFX 8_25)中打印HTML页面,但它以纵向打印,字体很小

printer.createPageLayout(Paper.A4, PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT);
PrinterJob job = PrinterJob.createPrinterJob(printer);
if (job != null) {
    System.out.println(job.getJobSettings().getPageLayout());
    webEngine.print(job);
    job.endJob();
}
Run Code Online (Sandbox Code Playgroud)

System.out显示纵向方向

纸张=纸张:A4(210 x 297毫米)尺寸= 594.90087890625x841.3598022460938 MM Orient = PORTRAIT leftMargin = 54.0 rightMargin = 54.0 topMargin = 54.0 bottomMargin = 54.0

我发现在横向模式下打印HTML页面的唯一方法是在打印之前调用打印作业的showPageSetupDialog方法.

printer.createPageLayout(Paper.A4, PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT);
PrinterJob job = PrinterJob.createPrinterJob(printer);
if (job != null) {
    if(job.showPageSetupDialog(null)) {
        System.out.println(job.getJobSettings().getPageLayout());
        webEngine.print(job);
        job.endJob();
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我在"页面设置"对话框中选择"横向",则会显示System.out

纸张=纸张:A4尺寸= 210.0x297.0 MM东方= LANDSCAPE leftMargin = 54.0 rightMargin = 53.11810302734375 topMargin = 51.995269775390625 bottomMargin = 54.0

我对话的问题在于我每次都必须设置A4和风景.

我有3个问题: - …

printing javafx javafx-8 javafx-webengine

0
推荐指数
1
解决办法
2308
查看次数

如何在表列上显示列表,列表项的字段很少

更新:此Qustion移动到 TableColumn应该只显示复杂数据类型的一个特定值,因为它更具体

我想填充一个Person包含复杂数据类型的表name,id并且a List<Person>.目前我得到一个表格正确name,id第三列有其他Persons 的全部信息,但它应该只显示Personss 的名称.有没有办法让我的第三列只显示Person.getName()值?

关键词,欢迎解决!非常感谢你!

编辑:代码

Person.class

public class Person {
    String id;
    String name;
    List<Person> friends;

public String getId() {...}
public String getName() {....}
public List<Person> getFriends {...}
}
Run Code Online (Sandbox Code Playgroud)

TableView.class

public TableView<Person> createTable() {
    TableColumn<Person, String> firstCol = new TableColumn<>("ID");
        TableColumn<Person, String> secondCol = new TableColumn<>("Name");
        TableColumn<Person, List<Person> thirdCol = new TableColumn<>("Friends");

        PropertyValueFactory<Person, String> firstColFactory = new PropertyValueFactory<>( …
Run Code Online (Sandbox Code Playgroud)

javafx tablecolumn javafx-8

0
推荐指数
2
解决办法
5527
查看次数