第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

無法將焦點(diǎn)設(shè)置在 JavaFX SwingNode 內(nèi)的 JTextPane 上

無法將焦點(diǎn)設(shè)置在 JavaFX SwingNode 內(nèi)的 JTextPane 上

縹緲止盈 2021-09-15 14:18:31
我正在嘗試將焦點(diǎn)設(shè)置在 JTextPane 上,以便在窗口打開時(shí)可以立即使用鍵盤進(jìn)行編輯。但是,我所做的一切似乎都沒有讓 JTextPane 專注于啟動。這只是將 JavaFX 與 Swing 結(jié)合使用的問題嗎?import javafx.collections.FXCollections;import javafx.collections.ObservableList;import javafx.embed.swing.SwingNode;import javafx.event.ActionEvent;import javafx.fxml.FXML;import javafx.scene.control.ListView;import javax.swing.*;public class TestDialog {    @FXML    private ListView listView;    @FXML    private SwingNode node;    private ObservableList<Integer> obsList;    @FXML    public void initialize(){        JTextPane pane = new JTextPane();        SwingUtilities.invokeLater(() -> pane.requestFocusInWindow());        pane.setText("This issue is not reproducible in JDK 8 early-access build (8u172) which is yet to be released.");        node.setContent(pane);         obsList = FXCollections.observableArrayList();        for(int x = 0; x < 12; x++){            obsList.add(x);        }        listView.setItems(obsList);        node.setFocusTraversable(true);        node.requestFocus();        pane.requestFocus();        pane.grabFocus();    }    @FXML    private void removeItem(ActionEvent event) {        obsList.remove(0);    }}
查看完整描述

2 回答

?
jeck貓

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊

我不知道這是否有幫助,但下面是我根據(jù)示例代碼制作的演示程序,出于某種原因,它對我有用:


import javafx.application.Application;

import javafx.application.Platform;

import javafx.collections.FXCollections;

import javafx.collections.ObservableList;

import javafx.embed.swing.SwingNode;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.scene.Scene;

import javafx.scene.control.ListView;

import javafx.scene.layout.StackPane;

import javafx.stage.Stage;

import javax.swing.*;   


public class Test extends Application {


    @FXML

    private ListView listView;

    @FXML

    private SwingNode node;


    private ObservableList<Integer> obsList;


    public static void main(String[] args) {    

        launch(args);

    }


    @Override

    public void start(Stage arg0) throws Exception {

        initialize(arg0);

    }


    @FXML

    public void initialize(Stage stage){        

        JTextPane pane = new JTextPane();


        // The program runs the same no matter if one of the below two lines are used or if neither are used

        //SwingUtilities.invokeLater(() -> pane.requestFocusInWindow());

        //Platform.runLater(() -> {node.requestFocus();});


        pane.setText("This issue is not reproducible in JDK 8 early-access build (8u172) which is yet to be released.");


        node = new SwingNode();

        node.setContent(pane);

        obsList = FXCollections.observableArrayList();

        for(int x = 0; x < 12; x++){

            obsList.add(x);

        }

        listView = new ListView();

        listView.setItems(obsList);


        node.setFocusTraversable(true);

        node.requestFocus();

        pane.requestFocus();

        pane.grabFocus();


        StackPane root = new StackPane();

        root.getChildren().add(node);

        Scene scene = new Scene(root, 500, 500);

        stage.setTitle("Test");

        stage.setScene(scene);

        stage.show();

    }


    @FXML

    private void removeItem(ActionEvent event) {

        obsList.remove(0);

    }

}



查看完整回答
反對 回復(fù) 2021-09-15
?
弒天下

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊

由于BWC_semaJ的解決方案,它現(xiàn)在可以工作了。而不是使用:

SwingUtilities.invokeLater(() -> pane.requestFocusInWindow());

我應(yīng)該使用:

Platform.runLater(() -> {swingNode.requestFocus();}); //Use this instead


查看完整回答
反對 回復(fù) 2021-09-15
  • 2 回答
  • 0 關(guān)注
  • 192 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號