那是不可能開箱即用。我創建了一個類我自己的,名爲MyMessageDialog要做到這一點:
https://gist.github.com/andydunkel/8914008
它基本上所有的從源代碼MessageDialog。然後,我已改寫了createMessageArea方法,並添加了鏈接,而不是一個標籤,並添加一個事件偵聽器:現在它
protected Control createMessageArea(Composite composite) {
// create composite
// create image
Image image = getImage();
if (image != null) {
imageLabel = new Label(composite, SWT.NULL);
image.setBackground(imageLabel.getBackground());
imageLabel.setImage(image);
//addAccessibleListeners(imageLabel, image);
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING)
.applyTo(imageLabel);
}
// create message
if (message != null) {
linkLabel = new Link(composite, getMessageLabelStyle());
linkLabel.setText(message);
linkLabel.addSelectionListener(new SelectionAdapter(){
@Override
public void widgetSelected(SelectionEvent e) {
System.out.println("You have selected: "+e.text);
try {
// Open default external browser
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(e.text));
}
catch (PartInitException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
catch (MalformedURLException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
}
});
GridDataFactory
.fillDefaults()
.align(SWT.FILL, SWT.BEGINNING)
.grab(true, false)
.hint(
convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH),
SWT.DEFAULT).applyTo(linkLabel);
}
return composite;
}
的MessageDialog可以用HTML代碼調用:
MyMessageDialog.openError(parent.getShell(), "Hehe", "<a href=\"http://google.com\">Google.com</a> Test");
不是一個很理想解決方案,但它的工作原理:
安迪
你是如何將鏈接作爲標籤的一部分?可能嗎?另外,有沒有更簡單的方法來做到這一點? – 2016-03-27 23:06:20
這會導致崩潰:PlatformUI.getWorkbench()。getBrowserSupport()。getExternalBrowser()。openURL(new URL(e.text)); 。它說:java.lang.ClassNotFoundException:org.eclipse.ui.testing.TestableObject \t at java.net.URLClassLoader.findClass(Unknown Source) – 2016-03-28 19:30:40