在 Mac OS X 上使用 JTable 进行拖放

Drag and Drop with JTable on Mac OS X(在 Mac OS X 上使用 JTable 进行拖放)
本文介绍了在 Mac OS X 上使用 JTable 进行拖放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 Mac 上遇到了 DnD 和 JTable 的问题.如果您启动以下程序并在表格中单击(快速),有时会选择某些内容,有时会在一段时间后执行 DnD 应用程序崩溃或至少 DnD 不会有可能了.我在 2 台 Mac 上对其进行了测试.

Java 版本:1.6.0_35Mac OS X:10.6.8

有人可以确认吗?有什么解决方法吗?

包tablednd;导入 javax.swing.JFrame;导入 javax.swing.JTable;导入 javax.swing.SwingUtilities;公共类 TableDnD {公共静态无效主要(字符串[]参数){SwingUtilities.invokeLater(new Runnable() {@覆盖公共无效运行(){对象[][] 数据 = {{玛丽",坎皮奥内",滑雪板",新整数(5),新布尔(假)},{艾莉森",Huml",划船",新整数(3),新布尔(真)},{"Kathy", "Walrath", "Chasing toddlers", new Integer(2), new Boolean(false)},{"Mark", "Andrews", "速读", new Integer(20), new Boolean(true)},{"Angela", "Lih", "教学高中", new Integer(4), new Boolean(false)}};String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};最终 JTable 表 = new JTable(data, columnNames);JFrame 框架 = 新的 JFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);table.setDragEnabled(true);框架.添加(表);框架.pack();frame.setLocationRelativeTo(null);frame.setVisible(true);}});}}

解决方案

在将拖动的行拖放到表格的其他任何位置时,我(有时)在 Mac OS X 10.5.8 中得到如下所示的错误.目标选择矩形保留在屏幕上,无法进行进一步的拖动操作.我不知道为什么,但我想一个单元格没有被识别为适合一行的目的地.

<上一页>2012-10-14 14:14:23.912 java[44061:10b] ***-[NSWindowViewAWT draggingEnded:]:无法识别的选择器发送到实例 0x1001e71402012-10-14 14:14:23.913 java[44061:10b] ***-[NSWindowViewAWT draggingEnded:]:无法识别的选择器发送到实例 0x1001e7140

将拖动的行放到另一个应用程序上可以按预期工作.

顺便说一句,的解决方案.

i have a problem with DnD and JTable on macs. If you start the following program and click (fast) around in the table, sometimes selecting something, sometimes do DnD after a while the application crashes or at least DnD will not be possible anymore. I tested it on 2 Macs.

Java version: 1.6.0_35 Mac OS X: 10.6.8

Does anyone can confirm this? Any workaround?

package tablednd;

import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.SwingUtilities;

public class TableDnD {
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            Object[][] data = {
                {"Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath", "Chasing toddlers", new Integer(2), new Boolean(false)},
                {"Mark", "Andrews", "Speed reading", new Integer(20), new Boolean(true)},
                {"Angela", "Lih", "Teaching high school", new Integer(4), new Boolean(false)}
            };

            String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};

            final JTable table = new JTable(data, columnNames);
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            table.setDragEnabled(true);
            frame.add(table);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
}
}

解决方案

When dropping a dragged row anywhere else on the table, I (sometimes) get the errors shown below back as far as Mac OS X 10.5.8. The target selection rectangle remains on the screen, and no further drag operations are possible. I'm not sure why, but I suppose a cell is not recognized as a suitable destination for a row.

2012-10-14 14:14:23.912 java[44061:10b] *** -[NSWindowViewAWT draggingEnded:]:
    unrecognized selector sent to instance 0x1001e7140
2012-10-14 14:14:23.913 java[44061:10b] *** -[NSWindowViewAWT draggingEnded:]:
    unrecognized selector sent to instance 0x1001e7140

Dropping the dragged row on another application works as expected.

As an aside, auto-boxing can simplify the initialization code:

Object[][] data = {
    {"Mary", "Campione", "Snowboarding", 5, false},
    {"Alison", "Huml", "Rowing", 3, true},
    {"Kathy", "Walrath", "Chasing toddlers", 2, false},
    {"Mark", "Andrews", "Speed reading", 20, true},
    {"Angela", "Lih", "Teaching high school", 4, false}
};

Addendum: This image shows the drag in progress; after triggering the anomaly, the gray rectangle remains immobile when the frame is dragged.

As a workaround, there is a solution to disable the grey rectangle altogether.

这篇关于在 Mac OS X 上使用 JTable 进行拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)