我在一个特定的列上创建了一个表和setcursor。在显示表格时,光标第一次正确显示,但如果表格模型更改并且表格被重新绘制,则根据代码不显示光标,而是在所有列上显示默认光标。JTable.SetCursor不改变光标
试过调试代码,调用jtable.setcursor得到正确执行,但光标不显示在屏幕上。
已通过MouseMoved()方法内的MouseMotionListener设置光标。
任何帮助表示赞赏。
我最近的观察:
我已经发现,当任何其他对话过来,显示表滚动面板的问题就出现了。如果JFileChooser或JDialog通过包含JScrollPane for JTable的面板启动,则在关闭JFileChooser或JDialog后,表中的游标不会按代码显示,即使在表模型根本没有更改的情况下也会发生。
以下是我的代码来设置光标:当模型改变列模型改变,以及和旧列实例不再有效
final Cursor handCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
final Cursor defaultCursor = Cursor.getDefaultCursor();
table.addMouseMotionListener(new MouseAdapter()
{
public void mouseMoved(MouseEvent e)
{
int cModel = table.columnAtPoint(e.getPoint());
int cView = table.convertColumnIndexToView(cModel);
if (cView == 1)
{
table.setCursor(handCursor);
}
else
{
table.setCursor(defaultCursor);
}
}
});
你能向我们展示'setCursor'到特定'TableColumn'的代码吗 – mKorbel
工作区 - 请展示一个短的可运行示例(又名:sscce),它演示了 – kleopatra
刚刚注意到你的转换 - 这可能不是你想要的:由columnAtPoint返回的列_is view_ coordinate,或者按原样或convertToModel – kleopatra