GUI Components (Widgets)

In the previous lecture, we discussed handling events from the mouse (and by analogy the keyboard, window manager, etc). Modern user interfaces abound with complex display and functional units. Although it is possible to build an entire GUI from scratch handling only the basic events, it is not only tedious and time comsuming. To save programmers from this chore, most GUI environments provide a set of pre-built library components that implement commonly used UI functionality. These GUI components (often called widgets) process the basic mouse and keyboard events in their windows and communicate with the rest of the program through a set of method calls (API) and by sending their own events (which are processed through the event queue just like the basic mouse and keyboard events).

There is another benefit to these widget sets besides saving the programmer some work. Programs using a particular Widget set will all tend to have similar "look-and-feel"-s and behave similarly. This is a great benefit to the user who can count on things to look the same and act the same between programs.

There are really no new paradigms or technologies involved in using widgets. They are created and added using the same methods we used for JPanels when discussing graphics. The event handling follows that used for the mouse events. The additional complexities introduced by GUI components are really to their variety, functionality, and sheer number per program. In particular, the issues are:

Much of the effort of GUI programming is combing the books and on-line documentation. There are around 20 component types in Java, we will only give a small sampling in this lecture, chosen to illustrate the basic points above. We are also going to postpone a discussion of layout for another time.

We are also going to ignore the whole issue of what makes a good GUI design. This is far beyond the scope of this course and is a field in itself ( there are many books on this subject, along with several journals and conferences).

Basic Components: Buttons

Text Input

Menus

Dialog boxes

Table Widget

Finally, we will end with a most complex widget that with a more complex model.

Postscript

There are many other interesting widgets including spinners, progress bars, toolbars, tree widgets, tab widget (one of my fav's), and HTML/RTF text widgets. Explore and have fun.