本文介绍了使用JSpinner像JTable单元格编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



单元格保持在NON-editable模式,直到我点击它,对于非编辑我的意思是我不能写入它(它没有集中,所以它不接受输入键盘),但我可以改变上下箭头(键盘)的值。



所以,当我按下一个键时,我必须做什么才能集中表格单元格?



除了这个问题,我的SpinnerEditor类工作得很好。



感谢所有。

解决方案


pre $ b public void focusGained(FocusEvent e){

//编辑器是((JSpinner.DefaultEditor)spinner.getEditor())。getTextField();
//必须设置焦点jspinner的文本组件
editor.requestFocus();

// this if yo你想选择jspinner的显示文本
SwingUtilities.invokeLater(new Runnable(){
public void run(){
System.out.println(run);
editor.selectAll();
}
});
}

public void focusLost(FocusEvent e){}
});


i'm using a JSpinner like a table cell editor, i have one annoying problem:

The cell remains in NON-editable mode until i click into it, for NON-editable i mean that i can't write into it(it has not focus so it doesn't accept inputs keyboard) but i can change the value with up-down arrows(of keyboard).

So, what i have to do to focus my table cell as soon as i press a key when it is selected?

Except for that problem my SpinnerEditor class works quite well.

Thanks all.

解决方案

Ok, my solution now is this:

spinner.addFocusListener(new FocusListener() {

    public void focusGained(FocusEvent e) {

        // editor is ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField();
        // necessary to set focus on the text component of jspinner
        editor.requestFocus();

        // this if you want to select the displayed text of jspinner
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                System.out.println("run");
                editor.selectAll();
            }
        });
    }

    public void focusLost(FocusEvent e) {}
});

这篇关于使用JSpinner像JTable单元格编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 03:44