Extreme Java G22.3033-007
Session 3 - Sub-Topic 1 Swing
Dr. Jean-Claude Franchitti
New York University Computer Science Department Courant Institute of Mathematical Sciences
Java Core Technologies
Q JFC Swing
1 What is Swing?
Q A GUI toolkit that simplifies and streamlines the development of windowing components (e.g., menus, toolbars, etc.)
Q Pluggable look-and-feel design (PL&F)
Q Platform specific look and feel with platform independent software
Q Swing components never rely on peer code
Q Lightweight components
Swing and AWT
Q Swing extends - but does not replace - the Abstract Windowing Toolkit (AWT)
Q AWT is a set of OO GUI classes
Q Swing extends the Lightweight UI Framework that became part of the Java AWT with the introduction of JDK 1.1
2 Swing is 100% Pure Java and Swing Beans
Q Components are 100% pure Java versions of AWT components (e.g., Button, Scrollbar, List, etc.)
Q Swing also include new higher-level components written in pure Java (e.g., tree- view, list-box, tabbed-pane components)
Q Swing is compatible with the JavaBeans specification
Swing and the JFC Library
Q The JCF Library includes the Swing component set
Q JFC also contains three major APIs:
Q Java 2D
Q advanced 2D graphics and imaging
Q Drag and Drop
Q data transfer across Java and native applications, and within a single Java application
Q Accessibility API
Q e.g., screen magnifiers, and audible text readers
3 Swing Architecture
Differences between AWT and Swing
Q Swing does not use any platform-specific implementations (such as AWT’s “peers”)
Q Swing creates its components using pluggable look-and-feel (PL&F or plaf)
Q Swing automatically plugs in the L&F module that matches its platform
Q Other L&F modules can also run in a given GUI
4 Differences between AWT and Swing (continued)
• L&F can be changed dynamically at runtime • The 3 other JFC APIs can be used in Swing programs in a 1.2/1.3 environment (real integration is planned for a future release)
The Three Parts of Swing
Q New set of components inheriting from JComponent
Q Jcomponent is a descendent form AWT’s Container class
Q Jcomponent is the root class of almost all Swing Component classes
Q Hierarchy allows Swing components to contain other components (component nesting)
5 The Three Parts of Swing (continued)
Q Group of Swing-related support classes
Q Vital services to the Swing API
Q Not used to create visible Swing components
Q New set of Swing-related interfaces implemented by Swing component classes and support classes
Swing & IFC
Q Best features of AWT and Netscape’s IFC (Internet Foundation Class) library are being integrated
Q Some similarity in the default look and feel of Swing and IFC widgets
Q Similarities are disappearing since L&Fs give Swing components different looks and feels in different implementations
6 Swing Component Gallery
JApplet - Border Interface - JButton - JCheckBox - JCheckBoxMenuItem
JColorChooser - JComboBox - ImageIcon - Jdialog - JFileChooser
JInternalFrame - Jlabel - JList - JMenu - JMenuBar - JOptionPane
Swing Component Gallery (cont.)
JPopupMenu - JProgessBar - JRadioButton - JRadioMenuItem - JScrollBar
JScrollPane - Jslider - JSplitPane - JTabbedPane - JTable
JTextArea - JTextField - JToggleButton - JToolBar - JToolTip - JTree
7 Swing’s Inheritance Hierarchy
Swing Component Hierarchy
Q More than 250 classes
Q More than 75 interfaces for creating lightweight, 100% pure Java GUI components
Q More than twice as many components as AWT
8 UI classes and non-UI classes
Q All UI-Swing component classes start with “J” and descend from JComponent
Q UI classes create visible components (e.g., buttons, menus, etc.)
Q Examples of non-UI classes
Q events classes, and model classes
Differences Between AWT & Swing
9 Differences Between AWT & Swing
Q In AWT: CheckBox served as a check-box class and a radio-button class
Q In Swing all buttons have three states (pressed, enabled, and selected)
Q It is easier to synchronize and coordinate menu events and button events in Swing (a single mouse click can activate or desactivate both a menu item and its toolbar button)
JComponent Class
10 Roots in MVC
New AWT/Swing Capabilities (J2SE 1.4)
Q AWT improvements
Q Mouse wheel support
Q High-perf. graphics to directly draw on the screen
Q Similar to DirectX (Windows) or Sun OpenGL (Solaris)
Q Swing
Q New formatted input components
Q JFormatterTextField, JSpinner
Q Seamless drag-and-drop support
Q Printing API
Q New Image I/O framework providing a pluggable architecture to load/save images
11