将 JXTable 与 RXTable 组合

2023-12-06

Problem

我想要的能力JXTable与“编辑时全选”行为RXTable。进行简单的覆盖就可以了,但是 RXTable 的双击功能不适用于 JXTable。当使用“按钮操作”模式时,这很好,但是当使用 F2 或双击 JXTable 中的某些内容时,会与 RXTable 发生冲突并删除选择,因此我保留默认行为。是因为它内部使用的 GenericEditor 还是其他原因?

如何让 JXTable 在 F2 上全选或双击编辑?

编辑:看起来只有当模型具有为 Integer 类型定义的列时才会发生这种情况。当为字符串或对象列定义时,它会按预期工作。

Solution

感谢 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();
                }
            });
        }

被记住了这个把戏当 JFormattedTextField 获得焦点时,如何选择它中的所有文本?- 不处理通过键入开始编辑时的情况,在这种情况下,内容不会被删除(与普通文本字段一样),但会添加新键。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 JXTable 与 RXTable 组合 的相关文章

随机推荐

  • JavaScript 对象文字表示法内部变量指向[重复]

    这个问题在这里已经有答案了 我有一个变量数组 我希望一个变量等于前一个变量 例如 var myVars var1 test var2 var1 alert myVars var2 输出 var1未定义 有什么想法吗 我确信这是某种变量范围限
  • MongoDB:更新数组中项目的字段以匹配该项目的另一个字段

    我有一个这样的数据结构 我们有一些centers A center有一些switches A switch有一些ports id ObjectId 561ad881755a021904c00fb5 Name center1 Switches
  • 为 iframe 页面创建上一个下一个按钮

    这个主题可能有很多代码 但我似乎正在寻找一种不基于历史的变体 是否可能 所以我有这个代码
  • 我可以在 SQL Server 中删除之前检查约束吗?

    我有以下情况 一个主表和许多其他表通过外键链接在一起 现在 当我想删除主表中的一行时 将会发生 ConstraintsViolation 这是有意且良好的 现在我希望能够在触发删除行事件之前检查 ConstraintsViolation 是
  • 致命错误:调用未定义的函数 mysqli_connect()

    两天来我一直在尝试解决这个问题 但不幸的是没有结果 让我告诉你我关于这个问题的故事 我在网站上构建了一个应用程序 该应用程序处理评论 但是 我试图将其放在另一个站点上 并且我从旧站点复制了 php 文件 sql 文件 并将它们移动到新站点
  • 从 Access 2007 传输到 Excel 2007 时排除列标题的代码

    这是我正在使用的代码 它工作正常 但我需要知道需要哪些附加代码来排除列标题 Private Sub Command104ContrDonatWeekly Click On Error GoTo Command104ContrDonatWee
  • UnitOfWork 等于 Transaction 吗?或者还不止于此?

    互联网上充满了有关UnitOfWork图案 即使如此也不例外 我还是不明白 以我的理解UnitOfWork Transaction in DB 就这样 仅此而已 它是否正确 我的困惑是由于它是如何在不同的环境中实现的ORMs NHibern
  • 正则表达式,按大写字母分割字符串但忽略 TLA

    我正在使用正则表达式 System Text RegularExpressions Regex Replace stringToSplit A Z 1 Trim 按大写字母分割字符串 例如 我的名字是西蒙 变成 我的名字是西蒙 我发现这在处
  • 自动为 Woocommerce 上购买的产品设置特定属性术语值

    我想在下订单并处于 暂停 状态时自动向订购的产品添加特定的属性值 之前设置 我销售独特的产品 并且我设置了 STOCK 属性和 Out Of Stock 缺货 值 当下订单并处于 暂停 状态时 我想自动更改订购产品的特色状态 并向其添加缺货
  • WCF 捕获异常“服务器未提供有意义的回复..”

    服务器调用后 我的客户端捕获异常并显示以下消息 服务器没有提供有意义的回复 这可能是由合同不匹配 会话过早关闭或内部服务器错误引起的 另外 请注意我尝试了配置WCF 服务器没有提供有意义的回复 但还是没用 请注意 我将服务调试到最后 并且数
  • Spring Boot 2:动态刷新属性不起作用

    我已经按照这个官方教程进行操作了入门集中配置使用 Spring Boot 2 0 0 RELEASE 和 Spring Cloud Finchley M8 但动态刷新属性 无需重新启动 不起作用 经过一些调试 我注意到在ContextRef
  • 使用 Backbone.js 的投票系统

    我有一个Book具有属性的模型upVotes Book可以从数据库 MongoDB 查询 修改实例 然后保存 如果用户对一本书进行投票 我会更新upVotes计数 并将整个模型保存回服务器 问题是 如果其他人在实例加载时间和保存实例时间之间
  • spring:escapeBody 导致无效的 JSON

    我试图转义 JSP 中的字符串以在 AJAX 调用上返回有效的 JSON 但是 spring escapeBody 标记未正确转义 JSON 的单引号 有效的 JSON 不应转义单引号 status success body
  • Spring数据中的@Transient不起作用

    I have Settlement entity Entity Table name settlement public class Settlement ManyToOne JoinColumn name subscription x p
  • 使用 Elmah 记录 WCF Web 服务的用户名

    我们正在使用描述的方法here使用 Elmah 记录我们的 Web 服务错误 这确实有效 但遗憾的是记录的用户名是空的 我们做了一些调试 发现在 ErrorHandler 中记录错误时HttpContext Current User具有正确
  • Windows Phone ApplicationBar BackgroundColor 属性样式 XamlParseException

    我的应用程序中有很多页面 我决定在 App Resources 中创建一个全局 ApplicationBar 样式 然而 当我尝试启动应用程序时 VS 给了我一个错误 The property BackgroundColor was not
  • 在 PHP 安装上启用 Mcrypt

    我使用 Apache 2 2 16 在 Windows 机器上安装了 PHP 5 2 14 通过 msi 安装 安装附带了 ext php mcrypt dll 和 libmcrypt dll 但当我取消注释时扩展名 php mcrypt
  • Sql PIVOT 和字符串连接聚合

    我想使用数据透视 SQL 查询来构造一个结果表 其中连接文本作为数据透视表的数据部分中的结果 即我使用简单的选择得到以下结果 Event Name Resource Type Resource Name Event 1 Resource T
  • web.xml 中使用 CharacterEncodingFilter 进行 Spring 编码

    stackoverflow com 上的编码 我的网站上的编码
  • 将 JXTable 与 RXTable 组合

    Problem 我想要的能力JXTable与 编辑时全选 行为RXTable 进行简单的覆盖就可以了 但是 RXTable 的双击功能不适用于 JXTable 当使用 按钮操作 模式时 这很好 但是当使用 F2 或双击 JXTable 中的