简体   繁体   English

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

[英]Drag and Drop with JTable on Mac OS X

i have a problem with DnD and JTable on macs. 我在Mac上有DnD和JTable的问题。 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. 如果您启动以下程序并在表格中单击(快速),有时选择某些内容,有时会在应用程序崩溃一段时间后执行DnD,或者至少DnD将无法再进行。 I tested it on 2 Macs. 我在2台Mac上测试过它。

Java version: 1.6.0_35 Mac OS X: 10.6.8 Java版本: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. 当将拖动的行放在桌子上的任何其他位置时,我(有时)会将下面显示的错误反馈到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 . 作为一种解决方法,有一种解决方案可以完全禁用灰色矩形

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM