Java SWT Link Tutorial with Examples
1. SWT Link
SWT Link represents the hyper links similar to the anchor links on the HTML.
// Create a Link
Link link = new Link(shell, SWT.NONE);
link.setText("Go to <a href=\"htpps://eclipse.org\">Eclipse</a> Home Page.");
// Event handling when users click on links.
link.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Program.launch("https:/eclipse.org");
}
});
2. SWT Link Example
The following example creates a hyperlink that when you click on it, it go to the home page of Eclipse (https://eclipse.org).
LinkDemo.java
package org.o7planning.swt.link;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;
public class LinkDemo {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("SWT Link (o7planning.org)");
RowLayout rowLayout= new RowLayout();
rowLayout.marginLeft=10;
rowLayout.marginTop=10;
shell.setLayout(new RowLayout());
// Create a Link
Link link = new Link(shell, SWT.NONE);
link.setText("Go to <a href=\"htpps://eclipse.org\">Eclipse</a> Home Page.");
// Event handling when users click on links.
link.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Program.launch("https:/eclipse.org");
}
});
shell.setSize(400, 250);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Java SWT Tutorials
- Java SWT FillLayout Tutorial with Examples
- Java SWT RowLayout Tutorial with Examples
- Java SWT SashForm Tutorial with Examples
- Java SWT Label Tutorial with Examples
- Java SWT Button Tutorial with Examples
- Java SWT Toggle Button Tutorial with Examples
- Java SWT Radio Button Tutorial with Examples
- Java SWT Text Tutorial with Examples
- Java SWT Password Field Tutorial with Examples
- Java SWT Link Tutorial with Examples
- Programming Java Desktop Application Using SWT
- Java SWT Combo Tutorial with Examples
- Java SWT Spinner Tutorial with Examples
- Java SWT Slider Tutorial with Examples
- Java SWT Scale Tutorial with Examples
- Java SWT ProgressBar Tutorial with Examples
- Java SWT TabFolder and CTabFolder Tutorial with Examples
- Java SWT List Tutorial with Examples
Show More