在SWT 3.0中的org.eclipse.swt.widgets中貌似新增了一个Link类,据API介绍可以实现类似超链的外观。
使用方法如:link.setText("please click <a href=\"http://www.csdn.net\">here</a>。");
但是,当鼠标点击时,却不会有任何反应。
难道还是要写鼠标的点击事件?我很困惑。如果还是要写listener,然后用诸如Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler http://www.csdn.net");这样的方法的话,那在widgets中增加这个Link类又有什么作用呢?那还不如直接用Label算了,反正都是要用listener的。难道Link的作用只是显示一个类似超链接的外观么?那href里的内容不是可以随便乱写,反正都没什么作用。疑惑中,恳请哪位大侠指点一下Link的用法。

解决方案 »

  1.   

    看看Link类里的addListener方法,肯定有响应你点击的方法接口。
      

  2.   

    addSelectionListener
    public void addSelectionListener(SelectionListener listener)Adds the listener to the collection of listeners who will be notified when the control is selected, by sending it one of the messages defined in the SelectionListener interface. 
    widgetSelected is called when the control is selected. widgetDefaultSelected is not called. 
    Parameters:
    listener - the listener which should be notified 
    Throws: 
    IllegalArgumentException - 
    ERROR_NULL_ARGUMENT - if the listener is null 
    SWTException - 
    ERROR_WIDGET_DISPOSED - if the receiver has been disposed 
    ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver 这就是Link的addListener方法,就是一个通用Listener啊
    现在越来越觉得Link就是一个能提供HyperLink外观的Label了,继续研究中。