100 likes | 334 Views
Lecture 29. Swing & the JFC – Advanced Java GUI. Java Foundation Classes (JFC). JFC consists of five API AWT Java 2D Java Accessibility Java Drag & Drop Swing. Versions. Java 1.0 - AWT 1.0, but no Swing (NB AWT 1.0 incompatible with Swing)
E N D
Lecture 29 Swing & the JFC – Advanced Java GUI
Java Foundation Classes (JFC) • JFC consists of five API • AWT • Java 2D • Java Accessibility • Java Drag & Drop • Swing
Versions • Java 1.0 - AWT 1.0, but no Swing (NB AWT 1.0 incompatible with Swing) • Java 1.1 - AWT 1.1, Swing as an add-on • Java 2 - Swing is core • Java 1.2 / 1.3 / 1.4 / 1.5 • Be particularly careful with applets – Swing will only work if a Java2 VM is present in the browser
What is Swing? • Swing is a component library • Based upon AWT 1.1 widgets and event model • AWT extended by JComponents and supporting classes • Analagous classes to AWT (mostly extended) • New classes
Swing vs AWT • Much larger than AWT • No native code • Most components (eg buttons, labels, lists etc) can display images as well as text • Text formatting allowed (HTML) • Better border control • Components do not have to be rectangular
Limitations of Swing • Large API • Be careful with mixing Swing with “heavyweight” non-Swing components. • Swing components are not “thread safe” • Swing components must be in a Swing container
javax.swing javax.swing.border javax.swing.colorchooser javax.swing.event javax.swing.filechooser javax.swing.plaf javax.swing.table javax.swing.text javax.swing.text.html javax.swing.text.rtf javax.swing.tree javax.swing.undo javax.accessibility Swing Packages
Content Panes • Swing containers are much more complex than AWT • All containers have “panes”, to which components are added • These are loosly similar to AWT panels, but have many other properties
Plugable User Interfaces • plaf - Plugable Look & Feel • Cross-platform look & feel (Metal) • Motif • OS Specific (eg Windows, Macintosh etc) • Customised look & feel
Converting AWT to Swing • Import main Swing package (import javax.swing) • Check threading issues(only modify components with their own methods) • Replace all AWT components with Swing equivalents • Modify methods as necessary • Change calls to add() and setLayout() methods to use panes of containers