JFace's TitleAreaDialog : JFace Dialog « SWT JFace Eclipse « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » SWT JFace Eclipse » JFace DialogScreenshots 
JFace's TitleAreaDialog
JFace's TitleAreaDialog

import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.jface.dialogs.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import java.io.*;

/**
 * This class demonstrates JFace's TitleAreaDialog class
 */
public class ShowMyTitleAreaDialog extends ApplicationWindow {
  /**
   * ShowCustomDialog constructor
   */
  public ShowMyTitleAreaDialog() {
    super(null);
  }

  /**
   * Runs the application
   */
  public void run() {
    // Don't return from open() until window closes
    setBlockOnOpen(true);

    // Open the main window
    open();

    // Dispose the display
    Display.getCurrent().dispose();
  }

  /**
   * Creates the main window's contents
   
   @param parent the main window
   @return Control
   */
  protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1true));

    // Create the button
    Button show = new Button(composite, SWT.NONE);
    show.setText("Show");

    final Shell shell = parent.getShell();

    // Display the TitleAreaDialog
    show.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        // Create and show the dialog
        MyTitleAreaDialog dlg = new MyTitleAreaDialog(shell);
        dlg.open();
      }
    });

    parent.pack();
    return composite;
  }

  /**
   * The application entry point
   
   @param args the command line arguments
   */
  public static void main(String[] args) {
    new ShowMyTitleAreaDialog().run();
  }
}


/**
 * This class shows an about box, based on TitleAreaDialog
 */
class MyTitleAreaDialog extends TitleAreaDialog {
  // The image to display
  private Image image;

  /**
   * MyTitleAreaDialog constructor
   
   @param shell the parent shell
   */
  public MyTitleAreaDialog(Shell shell) {
    super(shell);

    // Create the image
    try {
      image = new Image(null, new FileInputStream("java2s.gif"));
    catch (FileNotFoundException e) {
      // Ignore
    }
  }

  /**
   * Closes the dialog box Override so we can dispose the image we created
   */
  public boolean close() {
    if (image != nullimage.dispose();
    return super.close();
  }

  /**
   * Creates the dialog's contents
   
   @param parent the parent composite
   @return Control
   */
  protected Control createContents(Composite parent) {
    Control contents = super.createContents(parent);

    // Set the title
    setTitle("About This Application");

    // Set the message
    setMessage("This is a JFace dialog", IMessageProvider.INFORMATION);

    // Set the image
    if (image != nullsetTitleImage(image);

    return contents;
  }

  /**
   * Creates the gray area
   
   @param parent the parent composite
   @return Control
   */
  protected Control createDialogArea(Composite parent) {
    Composite composite = (Compositesuper.createDialogArea(parent);

    // Create a table
    Table table = new Table(composite, SWT.FULL_SELECTION | SWT.BORDER);
    table.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Create two columns and show
    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);

    // Add some data
    TableItem item = new TableItem(table, SWT.NONE);
    item.setText(0"Robert Harris");
    item.setText(1"Bobby");

    item = new TableItem(table, SWT.NONE);
    item.setText(0"Robert Warner");
    item.setText(1"Rob");

    item = new TableItem(table, SWT.NONE);
    item.setText(0"Gabor Liptak");
    item.setText(1"Gabor");

    one.pack();
    two.pack();

    return composite;
  }

  /**
   * Creates the buttons for the button bar
   
   @param parent the parent composite
   */
  protected void createButtonsForButtonBar(Composite parent) {
    createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
  }
}
           
       
Related examples in the same category
1. JFace's ProgressMonitorDialogJFace's ProgressMonitorDialog
2. JFace's MessageDialogJFace's MessageDialog
3. JFace's IconAndMessageDialog
4. JFace's InputDialogJFace's InputDialog
5. JFace's ErrorDialog classJFace's ErrorDialog class
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.