0

私は Java と SWT が初めてです。

TableViewerテーブルのデータを表示するために作成しました。

class myTable : TableViewer

myTableボタンを押して(ポップアップのような)ダイアログを開き、から任意の項目を選択したいTableViewer

ダイアログには、「OK」とキャンセルの 2 つのボタンが必要です。

Javaでそれを行う方法を知っていますか?私はダイアログを開くことを意味しますTableViewer

このための標準ウィジェットはありますか?

どのコンポーネントを使用する必要がありますか?

例はありますか?

4

1 に答える 1

2

最も単純なダイアログは、次のorg.eclipse.jface.dialog.Dialogようなものを使用するものです。

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

public class TestDialog extends Dialog
{
  public TestDialog(final Shell parentShell)
  {
    super(parentShell);
  }


  @Override
  protected Control createDialogArea(final Composite parent)
  {
    final Composite body = (Composite)super.createDialogArea(parent);

    final TableViewer viewer = new TableViewer(body, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);

    viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // TODO: Set TableViewer content and label providers
    // TODO: Set TableViewer input

    return body;
  }
}

あなたのコードでは、次のことを行います。

TestDialog dialog = new TestDialog(shell);

dialog.open();   // Displays the dialog in a popup window
于 2014-01-02T15:45:01.460 に答える