JDK8u40 で追加された Spinner と Dialog を試してみた。 とりあえず回避方法をみつけた。

JavaFX

JDK8u40 で追加された Spinner と Dialog を試してみた。

このエントリーで Arrow button をマウスクリックして操作した場合、呼び出す Dialog を Modality.APPLICATION_MODAL または Modality.WINDOW_MODAL に設定すると

Spinner のインクリメントもしくはデクリメントが止まらないという不思議な現象に悩まされました。

キーボードのカーソルキーでの操作では期待通りに正常に動きます。

なんでマウスで Arrow button をクリックして操作するといけないのか?

MousePressed がブロックされずに押しっぱなし状態で SpinnerBehavior クラスの startSpinning(boolean increment) の Timeline が動いちゃってるようです。

そこで、愚かなアイディアですが MouseReleased が発生してから Dialog を呼び出しちゃえってやってみたら期待通りに動いてくれました。

ごめんなさい。こんな方法しか思いつきませんでした。

と言うことでお終いです。

これってやっぱりバグなんだろうか?

追記:Jose Pereda さんよりコメントをいただきました。

それによると SpinnerSkin class に問題があるようです。

詳しくは Jose さんのコメントをご覧ください。

あわせてこの問題に対する素晴らしい解決方法を提示してくれましたのでエントリー本文にも記載させていただきます。

素晴らしいコードをありがとうございました。

Hatena タグ:

« »

Comment

  1. Jose Peredasays:

    2015年3月13日 2:54 AM

    The problem is in the SpinnerSkin class:

    incrementArrowButton.setOnMousePressed(e -> {
    getSkinnable().requestFocus();
    getBehavior().startSpinning(true);
    });

    This assumes the spinner keeps the focus all the time, which in the case of a modal dialog is not true.

    The proper solution should be added to the API, so an issue should be opened at Jira with this bug.

    Your solution works, but only if you are using the mouse. So with a keyboard you wouldn’t show the dialogs…

    This is my approach. You can get a (private API) SpinnerBehavior instance and check it for yourself:

    private SpinnerBehavior beh;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
    spinner.valueProperty().addListener((ov, oldValue, newValue) -> {
    if(beh==null){
    beh = (SpinnerBehavior)((SpinnerSkin)(spinner.getSkin())).getBehavior();
    spinner.focusedProperty().addListener((obs,b,b1)->{
    if(b && !b1){
    beh.stopSpinning();
    }
    });
    }

    });
    }

    Also I find annoying that if you spin with your mouse, it’s very very slow, while with the keyboard is really fast… There’s a timeline with 750ms delay for mouse, but no delay for keyboard.

    Best regards,
    Jose

    返信

Trackback

  1. [...] JDK8u40 で追加された Spinner と Dialog を試してみた。 とりあえず回避方法をみつけた。 [...]

Leave a Reply to Jose Pereda (or Cancel)

* が付いている項目は、必須項目です!

次の HTML タグと属性を利用できます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

*

Trackback URL