問題描述
我在 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 進行拖放的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!