【发布时间】:2012-10-04 14:22:48
【问题描述】:
我在 Mac 上遇到了 DnD 和 JTable 的问题。 如果您启动以下程序并在表格中单击(快速),有时会选择某些内容,有时会在一段时间后执行 DnD 应用程序崩溃或至少 DnD 不会 有可能了。我在 2 台 Mac 上对其进行了测试。
Java 版本:1.6.0_35 Mac OS X:10.6.8
有人可以确认吗? 有什么解决方法吗?
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);
}
});
}
}
【问题讨论】:
-
为sscce+1。
标签: java macos swing jtable drag-and-drop