FACTOID # 51: Two-thirds of the world's executions occur in China.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS   

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Swing (Java)

Example Swing widgets in Java 5.0+ for the X Window System. Font rendering may vary on different platforms.
Example Swing widgets in Java 5.0+ for the X Window System. Font rendering may vary on different platforms.

Swing is a GUI toolkit for Java. It is one part of the Java Foundation Classes (JFC). Swing includes graphical user interface (GUI) widgets such as text boxes, buttons, split-panes, and tables. Image File history File links Gui-widgets. ... Image File history File links Gui-widgets. ... KDE 3. ... In computer programming, widget toolkits (or GUI toolkits) are sets of basic building units for graphical user interfaces. ... Java is a programming language originally developed by Sun Microsystems and released in 1995. ... The Java Foundation Classes (JFC) are a graphical framework for building Java based graphical user interfaces (GUIs) that are portable to various computing platforms including Mac OS X, Linux and Windows. ... A graphical user interface (GUI) is a type of user interface which allows people to interact with a computer and computer-controlled devices which employ graphical icons, visual indicators or special graphical elements called widgets, along with text labels or text navigation to represent the information and actions available to... A widget (or control) is an interface component that a computer user interacts with, such as a window or a text box. ...


Swing widgets provide more sophisticated GUI components than the earlier Abstract Window Toolkit. Since they are written in pure Java, they run the same on all platforms, unlike the AWT which is tied to the underlying platform's windowing system. Swing supports pluggable look and feel – not by using the native platform's facilities, but by roughly emulating them. This means you can get any supported look and feel on any platform. The disadvantage of lightweight components is slower execution. The advantage is uniform behavior on all platforms. Software component representations: above the representation used in UML, below the representation commonly used by Microsofts COM objects. ... The Abstract Windowing Toolkit (AWT) is Javas platform_independent windowing, graphics, and user_interface widget toolkit. ... Java is a programming language originally developed by Sun Microsystems and released in 1995. ... Look and feel refers to design aspects of a graphical user interface - in terms of both colours, shapes, layout, typefaces, etc (the look); and, the behaviour of dynamic elements such as buttons, boxes, and menus (the feel). It is used in reference to both software and websites. ...

Contents

History

The Internet Foundation Classes (IFC) were a graphics library for Java originally developed by Netscape Communications Corporation and first released on December 16, 1996. The Internet Foundation Classes (IFC) were a graphics library for Java originally developed by Netscape Communications Corporation and first released on December 16, 1996. ... This page may meet Wikipedias criteria for speedy deletion. ... Netscape Communications Corporation was the publisher of the Netscape Navigator web browser as well as many other internet and intranet client and server software products. ... December 16 is the 350th day of the year (351st in leap years) in the Gregorian calendar. ... Year 1996 (MCMXCVI) was a leap year starting on Monday (link will display full 1996 Gregorian calendar). ...


On April 2, 1997, Sun Microsystems and Netscape Communications Corporation announced their intention to IFC with other technologies to form the Java Foundation Classes. In addition to the components originally provided by IFC, Swing introduced a mechanism that allowed the look and feel of every component in an application to be altered without making substantial changes to the application code. The introduction of support for a pluggable look and feel allowed Swing components to emulate the appearance of native components while still retaining the benefits of platform independence. This feature also makes it easy to have an individual application's appearance look very different from other native programs. April 2 is the 92nd day of the year (93rd in leap years) in the Gregorian calendar. ... Year 1997 (MCMXCVII) was a common year starting on Wednesday (link will display full 1997 Gregorian calendar). ... Sun Microsystems, Inc. ... Netscape Communications Corporation was the publisher of the Netscape Navigator web browser as well as many other internet and intranet client and server software products. ... The Java Foundation Classes (JFC) are a graphical framework for building Java based graphical user interfaces (GUIs) that are portable to various computing platforms including Mac OS X, Linux and Windows. ... Look and feel refers to design aspects of a graphical user interface - in terms of both colours, shapes, layout, typefaces, etc (the look); and, the behaviour of dynamic elements such as buttons, boxes, and menus (the feel). It is used in reference to both software and websites. ... Pluggable look and feel is a mecanism used in some Widget toolkits allowing to change the look and feel of a graphical user interface at runtime. ...


Originally distributed as a separately downloadable library, Swing has been included as part of the Java Standard Edition since release 1.2. The Swing classes are contained in the javax.swing package hierarchy. Java 2 Platform, Standard Edition (up til version 5. ... A Java package is a Java programming language mechanism for organizing classes into namespaces. ...


Architecture

Swing is a platform independent, Model-View-Controller GUI framework for Java. It follows a single-threaded programming model, and possesses the following traits: This article or section should include material from Model view controller triad Model-View-Controller (MVC) is a software architecture that separates an applications data model, user interface, and control logic into three distinct components so that modifications to the view component can be made with minimal impact to... GUI can refer to the following: GUI is short for graphical user interface, a term used to describe a type of interface in computing. ...

  • Platform independence: Swing is platform independent both in terms of its expression (Java) and its implementation (non-native universal rendering of widgets).
  • Extensibility: Swing is a highly partitioned architecture which allows for the 'plugging' of various custom implementations of specified framework interfaces: Users can provide their own custom implementation(s) of these components to override the default implementations. In general, Swing users can extend the framework by: extending existing (framework) classes; providing alternative implementations of core components.
  • Component-Oriented: Swing is a component-based framework. The distinction between objects and components is a fairly subtle point: concisely, a component is a well-behaved object with a known/specified characteristic pattern of behaviour. Swing objects asynchronously fire events, have 'bound' properties, and respond to a well known set of commands (specific to the component.) Specifically, Swing components are Java Beans components, compliant with the Java Beans Component Architecture specifications.
  • Customisable: Given the programmatic rendering model of the Swing framework, fine control over the details of rendering of a component is possible in Swing. As a general pattern, the visual representation of a Swing component is a composition of a standard set of elements, such as a 'border', 'inset', decorations, etc. Typically, users will programmatically customize a standard Swing component (such as a JTable) by assigning specific Borders, Colors, Backgrounds, etc., as the properties of the component. The core component will then use these property (settings) to determine the appropriate renderers to use in painting its various aspects. However, it is also completely possible to create unique GUI controls with highly customized visual representation. (Swing components support transparent rendering.)
  • Configurable: Swing's heavy reliance on runtime mechanisms and indirect composition patterns allow it to respond at runtime to fundamental changes in its settings. For example, a Swing-based application can change its look and feel at runtime. Further, users can provide their own look and feel implementation, which allows for uniform changes in the look and feel of existing Swing applications without any programmatic change to the application code.
  • Lightweight UI: The magic of Swing's configurability is also due to the fact that it does NOT use the native host OS's GUI controls for representation, but rather 'paints' its controls programmatically, through the use of Java 2D APIs. Thus, a Swing component does NOT have a corresponding native OS GUI 'peer', and is free to render itself in any way that is possible with the graphics APIs.

However, at its core, every Swing component relies on an AWT container, since (Swing's) JComponent extends (AWT's) Container. This allows Swing to plug into the host OS's GUI management framework, including the crucial device/screen mappings and user interactions (such as key presses, mouse movements, etc.) Swing simply 'transposes' its own (OS agnostic) semantics over the underlying (OS specific) components. So, for example, every Swing component paints its rendition on the graphic device in response to a call to component.paint(), which is defined in (AWT) Container. But unlike AWT components, which delegated the painting to their OS-native "heavy weight" widget, Swing components are responsible for their own rendering. JavaBeans are software components written in the Java programming language. ...


Further, this transposition and decoupling is not merely visual, and extends to the Swing's management of, and application of its own OS-indepenent semantics for, events fired within its component containment hierarchies.


Overall, the Swing Architecture delegates the task of mapping the various flavors of OS GUI semantics onto a simple, but generalized pattern to the AWT container. Then, building on that generalized platform, it establishes its own rich and complex GUI semantics, in form of the JComponent model.


(The interested reader is encouraged to review the source of Container.java and JComponent.java classes for further insights into the nature of the interface between Swing's lightweight components and AWT's heavyweight widgets.)

  • Loosely-Coupled/MVC: The Swing library makes heavy use of the Model/View/Controller software design pattern, which conceptually decouples the data being viewed from the user interface controls through which it is viewed. Because of this, most Swing components have associated models (which are specified in terms of Java interfaces), and the programmer can use various default implementations or provide their own. The framework provides default implementations of model interfaces for all of its concrete components.

Typically, Swing component model objects are responsible for providing a concise interface defining events fired, and accessible properties for the (conceptual) data model for use by the associated JComponent. Given that the overall MVC pattern is a loosely-coupled collaborative object relationship pattern, the model provides the programmatic means for attaching event listeners to the data model object. Typically, these events are model centric (ex: row inserted event in a table model) and are mapped by the JComponent specialization into a meaningful event for the GUI component. This article or section should include material from Model view controller triad Model-View-Controller (MVC) is a software architecture that separates an applications data model, user interface, and control logic into three distinct components so that modifications to the view component can be made with minimal impact to... In software engineering (or computer science), a design pattern is a general repeatable solution to a commonly occurring problem in software design. ... An interface defines the communication boundary between two entities, such as a piece of software, a hardware device, or a user. ...


For example, the JTable has a model called TableModel that describes an interface for how a table would access tabular data. A default implementation of this operates on a two-dimensional array. This article does not cite any references or sources. ...


The view component of a Swing JComponent is the object used to graphically 'represent' the conceptual GUI control. A distinction of Swing, as a GUI framework, is in its reliance on programmatically rendered gui controls (as opposed to the use of native host OS's GUI controls). (This distinction is a source of complications when mixing AWT controls, which use native controls, with Swing controls in a GUI.)


It must be noted that the typical use of Swing framework does not require the creation of custom models, as the framework provides a set of default implementations that are transparently, by default, associated with the corresponding JComponent child class in the Swing library. In general, only complex components such as tables and collection views may require customization of the default models provided.


(However, to get a good sense of the potential that the Swing architecture makes possible, consider the hypotethical situation where custom models for tables and lists are wrappers over DAO and/or EJB services.)


Finally, in terms of visual composition and management, Swing favors relative layouts (which specify the positional relationships between components) as opposed to absolute layouts (which specify the exact location and size of components). This bias towards 'fluid' visual ordering is a direct legacy of the development of Swing from the ashes of AWT (framework) and the associated assumptions regarding the Applet operating environment that framed the design and development of the original Java gui toolkit.


(Conceptually, this view of the layout management is quite similar to that which informs the rendering of HTML content in browsers, and addresses the same set of concerns that motivated the former.)


Look and feel

Swing allows one to specialize the look and feel of widgets, by modifying the default (via runtime parameters), deriving from an existing one, by creating one from scratch, or, beginning with J2SE 5.0, by using the skinnable Synth Look and Feel, which is configured with an XML property file. The look and feel can be changed at runtime, and early demonstrations of Swing would frequently provide a way to do this. Look and feel refers to design aspects of a graphical user interface - in terms of both colours, shapes, layout, typefaces, etc (the look); and, the behaviour of dynamic elements such as buttons, boxes, and menus (the feel). It is used in reference to both software and websites. ... A widget (or control) is an interface component that a computer user interacts with, such as a window or a text box. ... In computing, skins and themes are custom graphical appearances (GUIs) that can be applied to certain software and websites in order to suit the different tastes of different users. ... The Extensible Markup Language (XML) is a general-purpose markup language. ...


Relationship to AWT

Since early versions of Java, a portion of the Abstract Window Toolkit (AWT) has provided platform independent APIs for user interface components. In AWT, each component is rendered and controlled by a native peer component specific to the underlying windowing system. The Abstract Windowing Toolkit (AWT) is Javas platform_independent windowing, graphics, and user_interface widget toolkit. ...


By contrast, Swing components are often described as lightweight because they do not require allocation of native resources in the operating system's windowing toolkit. The AWT components are referred to as heavyweight components.


Much of the Swing API is generally a complementary extension of the AWT rather than a direct replacement. In fact, every Swing lightweight interface ultimately exists within an AWT heavyweight component because all of the top-level components in Swing (JApplet, JDialog, JFrame, and JWindow) extend an AWT top-level container. However, the use of both lightweight and heavyweight components within the same window is generally discouraged due to Z-order incompatibilities. Z-order is an ordering of overlapping two-dimensional objects, such as windows in a graphical user interface (GUI) or shapes in a vector graphics editor. ...


The core rendering functionality used by Swing to draw its lightweight components is provided by Java 2D, another part of JFC. In computing, Java 2D is an API for drawing two-dimensional graphics using the Java programming language. ...


Relationship to SWT

The Standard Widget Toolkit (SWT) is a competing toolkit originally developed by IBM and now maintained by the Eclipse Foundation. SWT's implementation has more in common with the heavyweight components of AWT. This confers benefits such as more accurate fidelity with the underlying native windowing toolkit, at the cost of an increased exposure to the native platform in the programming model. The Eclipse IDE, the first application to use SWT The Standard Widget Toolkit (SWT) is a graphical widget toolkit for the Java platform. ... International Business Machines Corporation (known as IBM or Big Blue; NYSE: IBM) is a multinational computer technology and consulting corporation headquartered in Armonk, New York, USA. The company is one of the few information technology companies with a continuous history dating back to the 19th century. ... The Eclipse Foundation leads the development of Eclipse, the open-source Java application platform and IDE. // In 2003–2004 the Eclipse Consortium, an unofficial consortium of software industry vendors led by IBM, founded The Eclipse Foundation, a not-for-profit legal entity to lead and develop Eclipse. ...


The advent of SWT has given rise to a great deal of division among Java desktop developers with many strongly favouring either SWT or Swing. Sun's development on Swing continues to focus on look and feel (PLAF) fidelity with each platform's windowing toolkit in the approaching Java SE 7 release (as of December 2006). In the meantime there are other sources of high-fidelity PLAFs, many of which are collected on the javootoo site. Java Platform, Standard Edition or Java SE (formerly known up to version 5. ... 2006 is a common year starting on Sunday of the Gregorian calendar. ...


There has been significant debate and speculation about the performance of SWT versus Swing; SWT's heavy dependence on JNI makes it slower when the GUI component and Java need to communicate data, but faster at rendering when the data model has been loaded into the GUI. Wikipedia does not yet have an article with this exact name. ...


SWT serves the Windows platform very well but is considered by some to be less effective as a technology for cross-platform development. By using the high-level features of each native windowing toolkit, SWT returns to the issues seen in the mid 90's (with toolkits like zApp, Zinc, XVT and IBM/Smalltalk) where toolkits attempted to mask differences in focus behaviour, event triggering and graphical layout. Failure to match behavior on each platform can cause subtle but difficult to resolve bugs that impact user interaction and the appearance of the GUI.


Example

The following is a Hello World program using Swing. A hello world program is a computer program that prints out Hello, world! on a display device. ...

 import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.EventQueue; public final class HelloWorld implements Runnable { public static void main(String[] args) { // Swing has its own dispatch thread, which is // distinct from the main JVM (launcher) thread. // This means that even if the (launcher) thread exited // (this) main method, the Swing GUI thread would // still be running, waiting to respond to user input, etc. // and if the user closes the window, then the program would // continue to run (due to the live gui thread). As of Java 6, the // GUI thread will automatically stop if all Components are hidden and // disposed. // // Execute all GUI code on the event dispatch thread, even initialization: EventQueue.invokeLater (new HelloWorld()); } public void run() { // Create frame with title "Hello, World!" JFrame f = new JFrame ("Hello, World!"); // Previously we typically attached a window listener to our main JFrame // and on windowClosing() event notification callback, we would // explicitly call System.exit(stat) or some other such nastiness. // The following is the new (clean) way of defining default close behavior // for a JFrame. The following will merely dispose the JFrame but it will not // stop the application unless *all* Windows are disposed. f.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE); // this stops the app on window close // (it is commented out.) // f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); // JFrame, which is the 'window' component of Swing, has an interesting feature: // it has a layered content architecture which (conceptually) allows for placement // of a component of the JFrame in a designated layer. The layers can be conceptually // viewed as a series of transparencies placed one above another in an overhead // projector. // Swing typically places user components (such as buttons, etc.) in what it calls its // 'content pane'. This pane is layer that is below most of the other (transparent) // layers. What are the layers for? Think of when you right-click on a control and it // 'pops' a contextual menu 'over' the original control; or, when you press 'help' for // a control or hover the mouse for a 'tool tip' and the information is 'placed over // the control'. How is that done? By rendering the information in a layer 'above' // the lower level 'content' pane. // So: // The standard way of adding a component to a 'multi-pane' container such as JFrame is // by first establishing a reference to its 'content pane' (which is, by default just a // JPanel with BorderLayout and adding the components the JFrame to the content pane // and NOT directly to the JFrame. (The latest Swing release however alters the // semantics of the JFrame.add(..) to assume convenient addition to the content pane). f.getContentPane().add (new JLabel("Hello, World!")); // Remember the relative layouts of Swing? // pack() tells the receiving container (here 'this' JFrame) // for it to optimally pack its components according to its layout. f.pack(); f.setVisible(true); } } 

See also

Project Looking Glass is a free software project under the GPL to create an innovative 3D desktop environment for Linux, Solaris, and Windows. ... The event dispatching thread (EDT) is a background thread used in Java to process events from the Abstract Windowing Toolkit (AWT) graphical user interface event queue. ... SwingWorker is a popular utility class developed by Sun Microsystems for the Swing library of the Java programming language. ... CookSwing is an open source Java library that converts an XML document into Java Swing GUI at runtime. ... In computer programming, widget toolkits (or GUI toolkits) are sets of basic building units for graphical user interfaces. ... swingLabs is a Sun Open source project proposing extensions to the Java Swing GUI toolkit. ... The Swing Application Framework (JSR 296) is a java specification for providing a simple application framework for Swing) applications. ... The Java Class Library is a set of dynamically loadable libraries that Java applications can call at runtime. ...

References

  • Matthew Robinson, Pavel Vorobiev: Swing, Second Edition, Manning, ISBN 1-930110-88-X
  • David M. Geary: Graphic Java 2, Volume 2: Swing, Prentice Hall, ISBN 0-13-079667-0
  • James Elliott, Robert Eckstein, Marc Loy, David Wood, Brian Cole: Java Swing, O'Reilly, ISBN 0-596-00408-7
  • Kathy Walrath, Mary Campione, Alison Huml, Sharon Zakhour: The JFC Swing Tutorial: A Guide to Constructing GUIs, Addison-Wesley Professional, ISBN 0-201-91467-0
  • Joshua Marinacci, Chris Adamson: Swing Hacks, O'Reilly, ISBN 0-596-00907-0

External links


  Results from FactBites:
 
oreilly.com -- Online Catalog: Java Swing, Second Edition (884 words)
As a general Swing reference, this book is very good; where it excels is at covering the numerous important aspects of Swing theory and application.
Java Swing gives you in-depth coverage of everything you need to know to take full advantage of Swing, providing detailed descriptions of every class and interface in the key Swing packages.
As a general Swing reference, this book is OK; where it excels is at covering the numerous important aspects of Swing theory and application.
What does “Swing is Slow” mean? (1897 words)
About Java: I believe it is the greatest development in programming languages because I finally do not need to care about memory, hardware and operating system anymore.
After Java 1.4, “Swing Slow” really means the screens do not paint completely because painting is not completing due to a long task running in the event handler thread.
Swing overhead for an average table rendering is not detectable by the monitor.
  More results at FactBites »

 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your location
Your comments
Please enter the 5-letter protection code


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.