JavaFX:OS停靠栏中的程序标题(例如,Ubuntu 19.10)

问题描述 投票:1回答:1

今天我面临以下问题:

我使用方法setTitle()设置primaryStage的标题。该标题正确显示在窗口中,但是当我将光标悬停在OS停靠栏中的程序图标上时,我只会看到主程序类的路径(请参见下面的屏幕截图)。我该如何解决?

Title in program windowtitle in OS dockbar。我使用此代码:

    @Override
    public void start(Stage stage) throws IOException {
        this.stage = stage;
        instance = this;
        // App initialization
        Parent root = FXMLLoader.load(SlimeBot.class.getClassLoader().getResource("fxml/Main.fxml"));
        Scene scene = new Scene(root, 800, 600);
        stage.setTitle("SlimeBot - Панель управления");
        stage.setScene(scene);
        stage.show();
    }

使用java.awt.Toolkit中的字段尝试设置标题:


    @Getter
    private static SlimeBot instance;

    static {
        try {
            Toolkit xToolkit = Toolkit.getDefaultToolkit();
            java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
            awtAppClassNameField.setAccessible(true);
            awtAppClassNameField.set(xToolkit, "SlimeBot - Панель управления");
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        launch(args);
    }

    @Getter
    private Stage stage;

    @Override
    public void start(Stage stage) throws IOException {
        this.stage = stage;
        instance = this;
        // App initialization
        Parent root = FXMLLoader.load(SlimeBot.class.getClassLoader().getResource("fxml/Main.fxml"));
        Scene scene = new Scene(root, 800, 600);
        stage.setTitle("SlimeBot - Панель управления");
        stage.setScene(scene);
        stage.show();
    }

}```
java javafx x11
1个回答
0
投票

Okey ..我尝试从您链接上的博客文章中获取代码,但没有任何改变。

@Override
public void start(Stage stage) throws IOException {
    this.stage = stage;
    instance = this;
    // App initialization
    Parent root = FXMLLoader.load(SlimeBot.class.getClassLoader().getResource("fxml/Main.fxml"));
    Scene scene = new Scene(root, 800, 600);
    stage.setTitle("SlimeBot - Панель управления");

    try {
        Toolkit xToolkit = Toolkit.getDefaultToolkit();
        Arrays.asList(xToolkit.getClass().getDeclaredFields()).forEach(s -> System.out.println(s));
        java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
        awtAppClassNameField.setAccessible(true);
        awtAppClassNameField.set(xToolkit, "SlimeBot - Панель управления");
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }

    stage.setScene(scene);
    stage.show();
}

[当我运行JavaFX应用程序时,我从X11收到小警告:

(java:5232): Gdk-WARNING **: 15:35:37.334: XSetErrorHandler() called with a GDK error trap pushed. Don't do that.

© www.soinside.com 2019 - 2024. All rights reserved.