You are previewing SWT: A Developer's Notebook.
O'Reilly logo
SWT: A Developer's Notebook

Book Description

The Eclipse platform continues to gain tremendous popularity as both a Java IDE and a Java platform for application programming. One of the core underpinnings of Eclipse is SWT, the Standard Widget Toolkit. This set of components can be used to develop graphical user interfaces in Java,and offer a native-code alternative to Java's Swing and AWT components. Incorporating the look and feel of whatever platform the code is run on, SWT offers a lightning-fast approach to building GUIs, all of which actually look like they belong on the platform on which they are run. But you already know what you want to do--so wading through the basics of user interface design, graphical components, and what a button does is simply a waste of time. Enter SWT: A Developer's Notebook. In typical Developer's Notebook style, you'll learn how to take SWT out for a spin, make it work for you, and turn it upside down, all without wasted words or space. Each lab in this notebook details a specific task; you can read from the first page to the last, look up just what you need to know, and even squeeze this book into your laptop bag as a quick reference when you forget how to create a multi-tabbed view. This book covers:

  • Downloading and configuring Eclipse and SWT

  • Menus, toolbars, and buttons

  • Building tabbed layouts and folders

  • SWT's unique coolbar control

  • Adding listeners and responding to events

  • Building a complete SWT-based application

Table of Contents

  1. SWT: A Developer’s Notebook
    1. The Developer’s Notebook Series
      1. Notebooks Are...
      2. Notebooks Aren’t...
      3. Organization
    2. Preface
      1. What’s Inside
      2. Conventions Used in This Book
      3. What You’ll Need
      4. Using Code Examples
      5. We’d Like to Hear from You
      6. Acknowledgments
    3. 1. Getting Started
      1. Downloading the SWT Library
        1. How do I do that?
      2. Configuring Eclipse for SWT Development
        1. How do I do that?
      3. Supplying the SWT Package to the Java Compiler
        1. How do I do that?
        2. What about...
      4. Specifying the Location of the Native Library
        1. How do I do that?
        2. What just happened?
        3. What about...
      5. Using swt.jar in Multiple Projects
        1. How do I do that?
        2. What about...
    4. 2. SWT Shells
      1. Creating a Simple Shell
        1. How do I do that?
      2. Executing the Example
        1. How do I do that?
        2. What just happened?
      3. Working with Shell Styles
        1. How do I do that?
        2. What about...
      4. Creating a Shell Styles Example
        1. How do I do that?
      5. Creating Child Shells
        1. How do I do that?
        2. What about...
      6. Creating Multiple Child Windows
        1. How do I do that?
      7. Opening True Dialogs
        1. How do I do that?
        2. What just happened?
      8. Setting the Shell Title Text
        1. How do I do that?
      9. Setting the Shell Icon
        1. How do I do that?
    5. 3. SWT Menus
      1. Creating the Menu Bar
        1. How do I do that?
        2. What just happened?
      2. Adding Drop-Down Menus
        1. How do I do that?
      3. Adding Separator Bars
        1. How do I do that?
      4. Creating a Complete Menu System
        1. How do I do that?
        2. What about...
      5. Adding Cascading Submenus
        1. How do I do that?
      6. Making Menus Perform the Intended Action
        1. How do I do that?
        2. What about...
      7. Working with Other Menu Item Styles
        1. How do I do that?
      8. Determining the State of CHECK and RADIO Menu Items
        1. How do I do that?
        2. What about...
      9. Adding Keyboard Shortcuts
        1. How do I do that?
      10. Creating Pop-Up Menus
        1. How do I do that?
    6. 4. SWT Toolbars
      1. Creating the Toolbar
        1. How do I do that?
        2. What just happened?
        3. How do I do that?
        4. What just happened?
        5. What about...
        6. How do I do that?
        7. What just happened?
        8. What about...
      2. Creating Toolbar Buttons
        1. How do I do that?
      3. Creating a Complete Toolbar Example
        1. How do I do that?
      4. Making the Buttons Work—Adding Listeners
        1. How do I do that?
        2. What about...
        3. What just happened?
      5. Adding Separators to Your Toolbar
        1. How do I do that?
      6. Adding Check and Radio ToolItems
        1. How do I do that?
        2. What just happened?
      7. Determining Whether a Check or Radio Button Is Selected
        1. How do I do that?
      8. Using Tool Tips
        1. How do I do that?
    7. 5. SWT Text Fields
      1. Adding Text Fields to a Shell
        1. How do I do that?
        2. What just happened?
      2. Adding a Border to a Text Field
        1. How do I do that?
      3. Positioning the Text Field
        1. How do I do that?
      4. Setting the Tab Order
        1. How do I do that?
      5. Setting the Text Size Limit
        1. How do I do that?
      6. Interacting with the Text in the Text Widget
        1. How do I do that?
      7. Populating Text Fields from a Database
        1. How do I do that?
        2. What about...
      8. Appending Text to a Text Field’s Contents
        1. How do I do that?
        2. What about...
      9. Creating Multiline Text Fields
        1. How do I do that?
      10. Wrapping Text
        1. How do I do that?
        2. What about...
      11. Adding Scrollbars
        1. How do I do that?
      12. Reacting to Text Events
        1. How do I do that?
      13. Performing Field Validation
        1. How do I do that?
        2. What just happened?
      14. Creating Display-Only Text Fields
        1. How do I do that?
        2. What about...
      15. Creating Password Fields
        1. How do I do that?
    8. 6. SWT Buttons
      1. Creating Push-Style Buttons
        1. How do I do that?
        2. What just happened?
      2. Responding to Button Clicks
        1. How do I do that?
      3. Creating Check Buttons
        1. How do I do that?
      4. Determining CHECK Button Status
        1. How do I do that?
      5. Adding Listeners to CHECK Buttons
        1. How do I do that?
      6. Using Radio-Style Buttons
        1. How do I do that?
        2. What just happened?
      7. Causing No Radio Button to be Selected
        1. How do I do that?
      8. Creating Toggle Buttons
        1. How do I do that?
      9. Determining the State of a Toggle Button
        1. How do I do that?
      10. Creating Arrow Buttons
        1. How do I do that?
        2. What just happened?
      11. Using Images with Buttons
        1. How do I do that?
      12. Setting Tool-Tip Text
        1. How do I do that?
      13. Enabling and Disabling Buttons
        1. How do I do that?
    9. 7. SWT Lists
      1. Creating a List
        1. How do I do that?
        2. What just happened?
      2. Adding Items to a List
        1. How do I do that?
      3. Inserting Items in the Middle of a List
        1. How do I do that?
      4. Populating a List from a Database
        1. How do I do that?
        2. What just happened?
      5. Removing Items from a List
        1. How do I do that?
        2. What about...
      6. Determining the Selected Items
        1. How do I do that?
      7. Determining the Selected Item with Multiple Selections
        1. How do I do that?
        2. What just happened?
      8. Causing an Item to Appear Selected
        1. How do I do that?
        2. What about...
      9. Changing an Item’s Text Value
        1. How do I do that?
      10. Adding Scrollbars to a List
        1. How do I do that?
    10. 8. The SWT Combo
      1. Creating a Combo List
        1. How do I do that?
      2. Adding Items to a Combo List
        1. How do I do that?
      3. Creating a Working Combo List
        1. How do I do that?
      4. Getting the Value of the Selected Item
        1. How do I do that?
      5. Programmatically Selecting an Item
        1. How do I do that?
      6. Removing Items from a Combo List
        1. How do I do that?
        2. What about...
      7. Adding Events to Combo Widgets
        1. How do I do that?
        2. What just happened?
      8. Allowing Additions to the Combo List
        1. How do I do that?
      9. Getting and Setting Text in the Text Portion of the Combo
        1. How do I do that?
      10. Setting the Maximum Length for Entries
        1. How do I do that?
      11. Deselecting Text
        1. How do I do that?
      12. Responding to Item Changes in the Combo
        1. How do I do that?
      13. Using the SIMPLE Style
        1. How do I do that?
    11. 9. SWT Layouts
      1. What Are the SWT Layouts?
      2. Attaching a Layout to a Container
        1. How do I do that?
      3. Filling the Entire Container with Widgets
        1. How do I do that?
        2. What just happened?
        3. What about...
      4. Changing Widget Placement in FillLayouts
        1. How do I do that?
      5. Lining Up Widgets Using RowLayout
        1. How do I do that?
        2. What about...
      6. Controlling Wrapping of Widgets with RowLayout
        1. How do I do that?
      7. Controlling Sizing of Widgets with RowLayout
        1. How do I do that?
      8. Creating Vertical Rows
        1. How do I do that?
      9. Creating a GridLayout
        1. How do I do that?
        2. What just happened?
        3. What about...
      10. Creating Column Headings
        1. How do I do that?
        2. What just happened?
      11. Controlling Widget Sizing and Alignment
        1. How do I do that?
        2. What just happened?
      12. Forcing Widgets to Span Multiple Cells
        1. How do I do that?
      13. The SWT FormLayout
      14. Creating a Simple Password Entry Form
        1. How do I do that?
        2. What just happened?
    12. 10. SWT Composites and Groups
      1. Subclassing the Composite Class
        1. How do I do that?
        2. What just happened?
      2. Using the TextPaneComposite Class on a Shell
        1. How do I do that?
      3. Using Composite Class Styles
        1. What about...
      4. Using the Group Class
        1. How do I do that?
        2. What just happened?
        3. What about...
      5. Creating Multiple Instances of a Composite Subclass
        1. How do I do that?
      6. Using Composites to Achieve Complex Designs
        1. How do I do that?
      7. An Alternate Approach
        1. How do I do that?
    13. 11. SWT Tabbed Folders
      1. Creating an Instance of TabFolder
        1. How do I do that?
      2. Creating the Individual Tabs
        1. How do I do that?
      3. Adding Widgets to the Tabs
        1. How do I do that?
      4. Creating a Complete Tabbed Folder Example
        1. How do I do that?
        2. What just happened?
      5. Setting a Default Tab
        1. How do I do that?
    14. 12. SWT Tables
      1. Creating a Simple Table
        1. How do I do that?
        2. What just happened?
        3. What about...
      2. Highlighting Rows upon Selection
        1. How do I do that?
      3. Allowing Multiple-Row Selection
        1. How do I do that?
      4. Selecting Items Programmatically
        1. How do I do that?
        2. The CHECK Style
        3. How do I do that?
      5. Changing the Background Color
        1. How do I do that?
        2. What just happened?
        3. What about...
      6. Creating a Searchable Table
        1. How do I do that?
      7. Setting the Background of a Single Cell
        1. How do I do that?
      8. Adding Find-and-Replace Functionality
        1. How do I do that?
        2. What just happened?
        3. What about...
    15. 13. SWT Trees
      1. Creating the Tree
        1. How do I do that?
      2. Adding Items to the Tree
        1. How do I do that?
      3. Adding Items to Other Items
        1. How do I do that?
      4. Creating a Full Tree Example
        1. How do I do that?
        2. What just happened?
      5. Using Images with TreeItem
        1. How do I do that?
      6. Changing the Image When the Item Is Expanded
        1. How do I do that?
        2. What just happened?
      7. Using Trees with Other Widgets
        1. How do I do that?
        2. What just happened?
      8. Working with Other Tree Styles
      9. Determining the Checked Item(s)
        1. How do I do that?
    16. 14. Other SWT Listeners
      1. Using KeyListener
        1. How do I do that?
        2. What just happened?
      2. Using MouseListener
        1. How do I do that?
        2. What just happened?
        3. What about...
      3. Working with the MouseEvent Class
        1. How do I do that?
        2. What about...
      4. Responding to Shift-Click Events
        1. How do I do that?
      5. Working with the MouseMoveListener
        1. How do I do that?
        2. What just happened?
      6. Using the MouseTrackListener
        1. How do I do that?
        2. What just happened?
    17. 15. SWT CoolBars
      1. Creating a CoolBar
        1. How do I do that?
        2. What just happened?
      2. Using Events with CoolBars
        1. How do I do that?
      3. Adding Widgets Other Than Buttons to the CoolBar
        1. How do I do that?
      4. Preventing the User from Rearranging the CoolBar
        1. How do I do that?
      5. Using ToolBars with CoolBars
        1. How do I do that?
        2. What just happened?
    18. 16. SWT Slider and ProgressBar
      1. The SWT Slider Class
        1. How do I do that?
        2. What just happened?
        3. What about...
      2. Using the SWT ProgressBar Class
        1. How do I do that?
        2. What just happened?
      3. Creating a Moving Progress Bar
        1. How do I do that?
    19. 17. SWT Standard Dialogs
      1. Using the SWT MessageBox Class
        1. How do I do that?
        2. What just happened?
      2. Using the SWT FileDialog Class
        1. How do I do that?
      3. Using the SWT FileDialog Class
        1. How do I do that?
      4. Using the SWT FileDialog Class
        1. How do I do that?
        2. What just happened?
        3. What about...
      5. The SWT ColorDialog Class
        1. How do I do that?
        2. What just happened?
        3. What just happened?
        4. What just happened?
        5. What just happened?
      6. Using the SWT FontDialog Class
        1. How do I do that?
        2. What just happened?
      7. Using the SWT PrintDialog Class
        1. How do I do that?
        2. What just happened?
    20. 18. A Complete SWT Application
      1. Designing the Application
      2. Developing the Application
        1. What just happened?
        2. What about...
      3. The End of the SWT Road
    21. Index
    22. Colophon