Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

How to put a hyperlink to SWT Label Text in Java

Hi,
How can I add a hyperlink to JAVA SWT  Label text.

When I click on this text in the label, I want the defaul browser to navigate to this site.


This is the code I haver and I want the "Help" to be link to a website:

        GridData gridDataBanner2 = new GridData(GridData.HORIZONTAL_ALIGN_END);
        CLabel banner2 = new CLabel(shell, SWT.CENTER);
        Color MtGreen = new Color (shell.getDisplay(), 240,240,240);
        banner2.setBackground(MtGreen); 
        
        FontData fontData2 = banner2.getFont().getFontData()[0];
        Font fontBanner2 = new Font(shell.getDisplay(), new FontData(fontData2.getName(),8, SWT.NORMAL));
        banner2.setFont(fontBanner2);
        banner2.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
        

        banner2.setText("Help");
        banner2.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_BLUE));
        banner2.setLayoutData(gridDataBanner2);

Open in new window



Thanks,
Avatar of Tolgar
Tolgar

ASKER

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You have a SWT control called "Link" which you can use to create a hyperlink kind of entity.

See below

Link link = new Link(shell, SWT.NONE);
link.setText("<a>Link</a>");
link.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent e)
            {
                //your code goes on selection
            }
        });