我想知道是否可以在鼠标上移时获取列表中的项目?我在网上搜索并找到了许多使用 X 和 Y 坐标但没有使用列表的 SWT 表示例.我基本上在做的是实现一个列表,其中项目的顺序可以通过拖放来更改.为此,我需要能够获取放置位置下的项目,以便我可以将该项目与拖动的项目交换.
I wanted to know if its possible to get the item in the list on mouse up? I searched online and found many examples for SWT table using the X and the Y coordinate but none using a list. What I am basically doing is implementing a list in which the order of the items can be changed by drag and drop. For this I need to be able to get the item under the drop location so that I can swap that item with the dragged item.
List#getItemHeight() 返回一个item所占区域的高度.有了这些信息和 getTopIndex(),您应该能够在给定的 x 和 y 坐标处计算项目.
List#getItemHeight() returns the height of the area one item occupies. With that information and getTopIndex()you should be able to compute the item at a given x and y coordinate.
list.addListener( SWT.MouseDown, new Listener() {
@Override
public void handleEvent( Event event ) {
int itemTop = 0;
for( int i = 0; i < list.getItemCount(); i++ ) {
if( event.y >= itemTop && event.y <= itemTop + list.getItemHeight() ) {
System.out.println( "Click on item " + list.getItem( list.getTopIndex() + i ) );
}
itemTop += list.getItemHeight();
}
}
} );
或者,您可以使用带有 setHeaderVisible( false ) 的单列表来模拟列表小部件.该表提供了更好的开箱即用拖放支持.
Alternatively you could use a single-columned table with setHeaderVisible( false ) to emulate a list widget. The table provides better drag and drop support out of the box.
这篇关于在 Mouse Up 上获取 SWT 列表中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
解析 ISO 8601 字符串本地日期时间,就像在 UTC 中Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期时间,就像在 UTC 中一样)
如何将公历字符串转换为公历?How to convert Gregorian string to Gregorian Calendar?(如何将公历字符串转换为公历?)
Java:GregorianCalendar 的最大值和最小值是什么/在哪Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
1582 年 10 月 15 日之前日期的日历到日期转换.公历Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日历到日期转换
java日历setFirstDayOfWeek不起作用java Calendar setFirstDayOfWeek not working(java日历setFirstDayOfWeek不起作用)
Java:获取当前星期几的值Java: getting current Day of the Week value(Java:获取当前星期几的值)