Java by API/org.eclipse.jface.dialogs/TitleAreaDialog
extends TitleAreaDialog
<source lang="java">
import java.io.FileInputStream; import java.io.FileNotFoundException; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.jface.window.ApplicationWindow; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.ruposite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; public class MainClass extends ApplicationWindow {
public MainClass() { super(null); } public void run() { setBlockOnOpen(true); open(); Display.getCurrent().dispose(); } protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText("Send Message"); shell.setSize(500, 400); MyTitleAreaDialog dlg = new MyTitleAreaDialog(shell); dlg.open(); } public static void main(String[] args) { new MainClass().run(); }
} class MyTitleAreaDialog extends TitleAreaDialog {
private Image image; public MyTitleAreaDialog(Shell shell) { super(shell); try { image = new Image(null, new FileInputStream("jface.gif")); } catch (FileNotFoundException e) { } } public boolean close() { if (image != null) image.dispose(); return super.close(); } protected Control createContents(Composite parent) { Control contents = super.createContents(parent); setTitle("About This Application"); setMessage("This is a JFace dialog", IMessageProvider.INFORMATION); if (image != null) setTitleImage(image); return contents; } protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); Table table = new Table(composite, SWT.FULL_SELECTION | SWT.BORDER); table.setLayoutData(new GridData(GridData.FILL_BOTH)); TableColumn one = new TableColumn(table, SWT.LEFT); one.setText("Real Name"); TableColumn two = new TableColumn(table, SWT.LEFT); two.setText("Preferred Name"); table.setHeaderVisible(true); TableItem item = new TableItem(table, SWT.NONE); item.setText(0, "Name 1"); item.setText(1, "Name 2"); item = new TableItem(table, SWT.NONE); item.setText(0, "Name 3"); item.setText(1, "Name 4"); item = new TableItem(table, SWT.NONE); item.setText(0, "Name 5"); item.setText(1, "Name 6"); one.pack(); two.pack(); return composite; } protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); }
}
</source>