In this chapter you will learn
1. What is
Swing in Java?
2. Advantage and Disadvantages of
3. Hierarchy of Swing
4. Commonly Used Methods of Swing
What is Swing in Java?
Swing lets you create platform independent GUI application in Java. It has rich set of libraries that allows you to create beautiful and robust GUI application.
Advantage of Swing
There are so many advantages of Swing that is listed below:
- Swing provides rich set of controls or components that are purely written in Java.
- Swing Application is platform independent whereas AWT is windows based.
- Swing also provides all the functionality of AWT.
- Swing component inherits look and feel and changes their appearance according to your base theme.
- It follows Model-View-Controller (MVC) architecture.
- Swing provides “EXTRA” for components, such as:
- Icons on many components
- Decorative border for components
- Tooltip for components
- Swing components are lightweight, flexible and faster than AWT.
- It provides Built-in double buffering.
- Swing provides paint debugging support for when you build your own components.
- Swing provides more powerful components such as tables, lists, scrollpanes, colorchooser, tabbedpane etc
Disadvantage of Swing
- Swing Requires Java 2 or a separate jar file.
- You need to careful while drawing components otherwise it might be slower than AWT.
- Swing looks like native components but it might not act exactly like native components.
Hierarchy of Swing
Swing Commonly Used Methods
|Add a tool tip that appears when the cursor is over the component|
|Set or get the font of the text on the component|
|Set or get whether the component is visible using true or false as the argument|
|Enable or disable the component using true or false as the argument.|
Check to see if a component is enabled or disabled.
|Set the component so it is filled with a background color.|
Check to see if a component is opaque.
|Set or get the component’s background color.|
|Set or get the text color.|
|Used to add and remove components|
|sets size of the component.|
|sets the layout manager for the component.|
|add a component on another component.|
|sets the visibility of the component. It is by default false.|
Don’t worry, you will use all these methods throughout this tutorial and very soon these methods will be memorize to you.
Next chapter is Where to Develop Swing Application. In this chapter you will know how to start with Swing and Where to write swing code.