如何在删除Java应用程序时更改光标 [英] How to change cursor when dropping into Java application
本文介绍了如何在删除Java应用程序时更改光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些问题,我只是不能弄清楚...
我正在写一个Swing Java应用程序与接受拖放的JList。我想通过Java应用程序从我的系统拖动文件或文件夹时更改光标。
I'm having some problems I just can't figure out... I'm writing a Swing Java application with a JList that accepts drag-and-drops. I want to change the cursor while dragging a file or folder from my system over the Java application.
推荐答案
我自己找到了...感谢克林顿回答。这是我使用的:
I've found it myself... Thanks Clinton for answering though. Here's what I've used:
首先创建JList ...你都知道如何做...
然后我添加了一个setDropTarget :
first create the JList... You all know how to do that... Then I've added a setDropTarget:
lstFiles.setDropTarget(new DropTarget()
{
@Override
public synchronized void drop(DropTargetDropEvent dtde)
{
this.changeToNormal();
//handle the drop... [...]
}
@Override
public synchronized void dragEnter(DropTargetDragEvent dtde)
{
//Change cursor...
Cursor cursor = new Cursor(Cursor.HAND_CURSOR);
setCursor(cursor);
//Change JList background...
lstFiles.setBackground(Color.LIGHT_GRAY);
}
@Override
public synchronized void dragExit(DropTargetEvent dtde)
{
this.changeToNormal();
}
private void changeToNormal()
{
//Set cursor to default.
Cursor cursor = new Cursor(Cursor.DEFAULT_CURSOR);
setCursor(cursor);
//Set background to normal...
lstFiles.setBackground(Color.WHITE);
}
});
这篇关于如何在删除Java应用程序时更改光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文