問題描述
我在 Mac 上遇到了 DnD 和 JTable 的問題.如果您啟動(dòng)以下程序并在表格中單擊(快速),有時(shí)會(huì)選擇某些內(nèi)容,有時(shí)會(huì)在一段時(shí)間后執(zhí)行 DnD 應(yīng)用程序崩潰或至少 DnD 不會(huì)有可能了.我在 2 臺(tái) Mac 上對(duì)其進(jìn)行了測試.
Java 版本:1.6.0_35Mac OS X:10.6.8
有人可以確認(rèn)嗎?有什么解決方法嗎?
包tablednd;導(dǎo)入 javax.swing.JFrame;導(dǎo)入 javax.swing.JTable;導(dǎo)入 javax.swing.SwingUtilities;公共類 TableDnD {公共靜態(tài)無效主要(字符串[]參數(shù)){SwingUtilities.invokeLater(new Runnable() {@覆蓋公共無效運(yùn)行(){對(duì)象[][] 數(shù)據(jù) = {{瑪麗",坎皮奧內(nèi)",滑雪板",新整數(shù)(5),新布爾(假)},{艾莉森",Huml",劃船",新整數(shù)(3),新布爾(真)},{"Kathy", "Walrath", "Chasing toddlers", new Integer(2), new Boolean(false)},{"Mark", "Andrews", "速讀", new Integer(20), new Boolean(true)},{"Angela", "Lih", "教學(xué)高中", 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);}});}}
在將拖動(dòng)的行拖放到表格的其他任何位置時(shí),我(有時(shí))在 Mac OS X 10.5.8 中得到如下所示的錯(cuò)誤.目標(biāo)選擇矩形保留在屏幕上,無法進(jìn)行進(jìn)一步的拖動(dòng)操作.我不知道為什么,但我想一個(gè)單元格沒有被識(shí)別為適合一行的目的地.
<上一頁>2012-10-14 14:14:23.912 java[44061:10b] ***-[NSWindowViewAWT draggingEnded:]:無法識(shí)別的選擇器發(fā)送到實(shí)例 0x1001e71402012-10-14 14:14:23.913 java[44061:10b] ***-[NSWindowViewAWT draggingEnded:]:無法識(shí)別的選擇器發(fā)送到實(shí)例 0x1001e7140將拖動(dòng)的行放到另一個(gè)應(yīng)用程序上可以按預(yù)期工作.
順便說一句,的解決方案.
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.
這篇關(guān)于在 Mac OS X 上使用 JTable 進(jìn)行拖放的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!