View RSS Feed


Swing Architecture

  1. Designing a Swing GUI

    by , 04-26-2012 at 08:47 PM
    For simpler GUI designs, discussed above MVC widget internals could be ignored. Widget placement can be approached in GUI along with Swing similarly as AWT: by widget’s instantiation and their addition to the containers. In addition to this, MVC is used by two techniques for designing powerful and flexible GUIs.

    1. Simpler GUI Design: Widgets are instantiated and added to container. Then selection of Look & Feel is done for whole GUI.
    2. Complex GUI Design: Though Swing directly
  2. Component Architecture and MVC

    by , 04-26-2012 at 08:46 PM
    MVC’s common variation is used to present components by Swing where controller and view get combined to form an object known as delegate. Delegates present model and also translates the input of user into model, just like it is done by a controller. Communication that takes place b/w controller and view is found to be very complex. Two simplifies are combined, for the component design.

    For example, checkbox widget shall be considered. It consists of a state which could be true or ...
  3. Stateless vs. stateful delegates

    by , 04-26-2012 at 08:45 PM
    Methods which are present at ComponentUI use JComponent object, as a parameter. UI delegate’s stateless implementation is enabled by this convention. Implementation of stateless UI delegate permits one instance of UI delegate, to get used for component class’s instances. This would be reducing no. of objects that get instantiated.
    Suck kind of approach is for various simple GUI components. However, in case of more complexed components, it is not considered as “win” as inefficiency is created ...
  4. Distinguishing between UI-set and app-set properties

    by , 04-26-2012 at 08:44 PM
    Swing. Therefore this would be a critical thing to ensure that values don’t clobber when component’s default properties are set up by Look and Feel, for the component.
    This issue doesn’t arise when UI delegate first time is installed, at the component as properties are uninitialized and ultimately would be settled legally by Look&Feel. When individual properties are set after construction of component & subsequently new setup of Look and Feel takes place, such problem arises. Hence, ...
  5. The look-and-feel packages

    by , 04-26-2012 at 08:43 PM
    Swing.plaf, ScrollBarUI, ButtonUI etc which are present in UI delegates defines the accurate API which can be used by a component for interaction with instance of UI delegate. It shall be noted that originally interfaces were used here but got replaced by abstract classes as it was being felt that API was immature to with-stand interface’s concrete casting. Implementation of look and feel’s root is plaf APIs.

    Every implementation of look and feel gives abstract plaf classes’s concrete ...
  6. Managing look-and-feel data

    by , 04-26-2012 at 08:42 PM
    A static class known as UIManager.LookAndFeelInfo is defined by UIManager to store high leveled names, like Metal, and specified classname like "", for LookAndFeel.Internally these classes are used for management of the LookAndFeel objects which are known. UIManager could access this information through these given static methods:
    Java Code:
       public static LookAndFeelInfo[]
       public static
  7. Dynamically Changing the Default Look-and-Feel

    by , 04-26-2012 at 08:41 PM
    When look and feel is being set programmatically by the Swing application as it has been discussed above, the ideal place considered is before instantiation of the Swing components. This happens as the particular LookAndFeel is made current default by UIManager.setLookAndFeel() method, by initializing or loading the LookAndFeel instance, however components are not automatically caused to make their look & feel changed.

    It shall be noticed that UI delegates are initialized ...
  8. The 'default' look and feel

    by , 04-26-2012 at 08:41 PM
    Methods are provided by UIManager to set or get the current, default Look & feel.
    Java Code:
    public static LookAndFeel 
       public static void
          setLookAndFeel(LookAndFeel newLookAndFeel)
       public static void 
          setLookAndFeel(String className)
    Being default look & feel, cross platformed look and feel of Java which is called “Metal” is initialized by the Swing. But if default look ...
  9. Look-and-feel management

    by , 04-26-2012 at 08:40 PM
    An abstract look and feel class is defined by Swing which present all central information to the implementation of look and feel, like description, name, whether look and feel is native or not, a hash table to store default values for different attributes of look and feel, like fonts and colors.

    Every implementation of look and feel defines the LookAndFeel subclass. For instance, swing.plaf.motif.MotifLookAndFeel provides Swing along with important details for management of look & ...
  10. The component hooks

    by , 04-26-2012 at 08:39 PM
    Look and feel behavior of every swing component defines swing.plaf package’s abstract class for representation of UI delegate. These classes naming convention is taking class name for sake of component, append UI and remove prefix

    In constructor of component, UI delegate is made, of which access is given as “JavaBeans” bound property, at the component. For instance, following methods are provided by JScrollBar for access of UI delegate.

    Java Code:
       public ScrollBarUI
  11. Pluggable look-and-feel architecture

    by , 04-26-2012 at 08:38 PM
    Look and feel, plugable architecture of swing provides one component API, with no dictation of look and feel. A default look and feel set is provided by the swing toolkit. API is considered as “open”, a design which allows additionally developers to make new implementations of look and feel, either by extension of present look and feel or by creating a new one. Pluggable look and feel is although extensible but it was designed intentionally at that level lower than basic component API. This is done ...
  12. Model change notification

    by , 04-26-2012 at 08:37 PM
    Any interested parties shall be notified by the modes when value or data gets changed. JavaBeans Event model is used by the Swing models for notification implementation. Two approaches used in Swing for this notification:

    • A lightweighted notification shall be sent which has been changed by the state and listener is required to rsend back the query to model for determining what has changed. This approach has an advantage that one event instance might be used from a particular model
  13. Application-data models

    by , 04-26-2012 at 08:36 PM
    Application data models are those interfaces which represent certain data that is quantifiable and it has meaning in application’s context like a cell present in table or items that have been displayed in some list. Such data models give quite powerful paradigm of programming for the swing programs, which require clear separation b/w GUI and application logic/data. For Swing components which are truly data centric like JTable and JTree, interaction is strongly recommended with data model. Application ...
  14. GUI-state models

    by , 04-26-2012 at 08:36 PM
    GUI state models are considered as those interfaces that are involved in defining the GUI control’s visual status. Like a button is armed or pressed, or which items in a list shall be chosen. Typically, GUI state models are just relevant in GUI context. It is also useful for development of programs by using separation of GUI state mode, specially when multiple controls of GUI have been associated with one common state. Or, when one control’s manipulation will be changing the another’s value automatically. ...
  15. Java Swing Roots in MVC

    by , 04-26-2012 at 08:35 PM
    In MVC i.e. Model view controller design, swing architecture has been rooted which dates back, to SmallTalk. MVC calls visual applications to be separately broken into 3 parts:
    • A Model- to present data, for application.
    • The view which is data’s the representation.
    • A controller – to take user input & translates them into changes present in model.

    MVC was considered as a logical choice earlier for Swing as bas was provided to meet up 1st three design goals, by staying ...
  16. Java Swing Design Goals

    by , 04-26-2012 at 08:34 PM
    Swing project has following goal:

    To build a set of extensible GUI components to enable developers to more rapidly develop powerful Java front ends for commercial applications.

    Design goals were established by the Swing team earlier in project, which resulted into architecture. Guidelines are:
    1. In java, easy maintenance and class platform consistency could be promoted by being implemented.
    2. Single API shall be provided which is able to support various look
  17. JTable MVC

    by , 01-08-2012 at 01:34 PM
    Swing uses a modified version of Model View Controller design pattern. Model, view and controller layers are separated by MVC design pattern.

    Name:  62.JPG
Views: 1786
Size:  19.7 KB

    Swing MVC Architecture

    • Component (JTable, JTree, and JList): These components coordinate.
    • Model (TableModel): charged with storing the data.
    • UIDelegate: It is responsible for getting the data from model and rendering it to screen.
    Tags: jtable, mvc Add / Edit Tags
    Architecture , JTable
  18. Swing Hierarchy

    by , 01-08-2012 at 01:31 PM
    All the Swing components start with ‘J’. Following diagram shows the swing hierarchy. JComponent is the base class for all components.

    Name:  62.JPG
Views: 5070
Size:  42.4 KB

    Swing Hierarchy
  19. Swing Action architecture

    by , 01-08-2012 at 01:28 PM
    Shared behavior between different user interfaces components are implemented by “Swing Action Architecture”. Like tool bar buttons and menu items perform same actions. All the components are disabled when an action is disabled.

    Java Code: Swing Action Architecture
    class FileAction extends AbstractAction {
    FileAction(String name) {
    public void actionPerformed(ActionEvent ae){
    //add action logic here
    JMenu fileMenu

    Updated 01-14-2012 at 07:56 PM by Java Swing

    Architecture , Actions
  20. AWT vs. Swing

    by , 01-08-2012 at 01:23 PM
    Swing contains a rich set of components as compared to AWT. They are purely build in Java and has following benefits as compared to AWT.

    • Swing contains extra components like JTree, JTable etc.
    • They can change skin based on current look and feel.
    • They follow the MVC design pattern and are more flexible.
    • Swing provided light weight components.
    • Swing provides double buffering.
    • Swing provides paint debugging.

    Swing has following ...
    Tags: awt, swing Add / Edit Tags