java – 将JXTable与RXTable结合使用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 将JXTable与RXTable结合使用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2631字,纯文字阅读大概需要4分钟。
内容图文
![java – 将JXTable与RXTable结合使用](/upload/InfoBanner/zyjiaocheng/696/7eae0743d94a476b98f81eef3e696a4b.jpg)
问题
我希望JXTable的功能具有RXTable的“select all on edit”行为.做一个简单的覆盖就可以了,但是RXTable的双击功能不适用于JXTable.当使用按钮动作模式时它很好,但是当使用F2或双击JXTable中的某些内容与RXTable冲突并删除选择时,我将保留默认行为.是因为它在内部使用的GenericEditor还是其他东西?
如何让JXTable在F2上选择全部或双击编辑?
编辑:看起来这只发生在模型具有为Integer类型定义的列时.当为String或Object列定义时,它按预期工作.
解
感谢kleopatra的修复,我能够改变selectAll方法,因此它处理JFormattedTextFields和所有编辑案例.由于原始代码适用于要编辑的类型,我只是将修复程序用于其他情况.这就是我最终的结果.
用以下内容替换RXTable中的selectAll:
/*
* Select the text when editing on a text related cell is started
*/
private void selectAll(EventObject e)
{
final Component editor = getEditorComponent();
if (editor == null
|| ! (editor instanceof JTextComponent
|| editor instanceof JFormattedTextField))
return;
if (e == null)
{
((JTextComponent)editor).selectAll();
return;
}
// Typing in the cell was used to activate the editor
if (e instanceof KeyEvent && isSelectAllForKeyEvent)
{
((JTextComponent)editor).selectAll();
return;
}
// If the cell we are dealing with is a JFormattedTextField
// force to commit, and invoke selectall
if (editor instanceof JFormattedTextField) {
invokeSelectAll((JFormattedTextField)editor);
return;
}
// F2 was used to activate the editor
if (e instanceof ActionEvent && isSelectAllForActionEvent)
{
((JTextComponent)editor).selectAll();
return;
}
// A mouse click was used to activate the editor.
// Generally this is a double click and the second mouse click is
// passed to the editor which would remove the text selection unless
// we use the invokeLater()
if (e instanceof MouseEvent && isSelectAllForMouseEvent)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
((JTextComponent)editor).selectAll();
}
});
}
}
private void invokeSelectAll(final JFormattedTextField editor) {
// old trick: force to commit, and invoke selectall
editor.setText(editor.getText());
SwingUtilities.invokeLater(new Runnable() {
public void run() {
editor.selectAll();
}
});
}
解决方法:
快速破解三种选择类型中的两种
// in selectAll(EventObject) special case the formatted early
if (editor instanceof JFormattedTextField) {
invokeSelectAll(editor);
return;
}
private void invokeSelectAll(final JFormattedTextField editor) {
// old trick: force to commit, and invoke selectall
editor.setText(editor.getText());
SwingUtilities.invokeLater(new Runnable() {
public void run() {
editor.selectAll();
}
});
}
记住了How to select all text in a JFormattedTextField when it gets focus?的技巧 – 在通过输入开始编辑时没有处理这种情况,在这种情况下,内容不会被删除(正常文本字段),但新密钥被添加.
内容总结
以上是互联网集市为您收集整理的java – 将JXTable与RXTable结合使用全部内容,希望文章能够帮你解决java – 将JXTable与RXTable结合使用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。