トップ 差分 一覧 ソース 検索 ヘルプ RSS ログイン

Link

SWT 3.1で追加されたorg.eclipse.swt.widgets.LinkはHTMLのリンク風ウィジェットです。ボタンの代わりに使うことができます。

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class LinkExample {

    private Shell shell = null;
    private Link link = null;
    private Text text = null;

    public static void main(String[] args) {
        Display display = Display.getDefault();
        LinkExample thisClass = new LinkExample();
        thisClass.createShell();
        thisClass.shell.open();

        while (!thisClass.shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }

    private void createShell() {
        shell = new Shell();
        shell.setText("Link Example");
        shell.setLayout(new GridLayout());
        
        link = new Link(shell, SWT.NONE);
        link.setText("<a>リンク</a>");
        link.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                text.setText("リンクがクリックされました。");
            }
        });
        link.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        
        text = new Text(shell, SWT.BORDER);
        text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        
        
    }

}

Linkにセットする文字列は<a>...</a>で囲む必要があります。

最終更新時間:2006年06月24日 16時21分41秒