在 Mac OS X 上使用 JTable 进行拖放 [英] Drag and Drop with JTable on Mac OS X

查看:34
本文介绍了在 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 进行拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆