Look, Read, Understand, Apply



Swing (Java)

Swing is Graphical User Interface (GUI) widget for Java, it is an Application Programmer Interface (API) for developing GUI for Java programs. Swing provides more sophisticated set of GUI components than Abstract Window Toolkit (AWT). It has several components like buttons, checkboxes, textboxes, list, tabbed panel, scroll panel, tree, tables etc. Swing is not implemented by platform-specific code; it is written entirely in Java and is platform-independent.

Swing components are lightweight as they do not need allocation of native resources in the operating system’s windowing toolkit. Swing is a part of Java Foundation Classes. Java foundation classes (JFC) is an API for Java programs to create GUI.

GUI in Java Swing is created by first creating a container; basically, Frame is used to create container. Containers are those components on which other components can be added. The Java Swing components can be added to the container classes. Java Swing containers are:

  • Panel: it is not a window in itself, it is used to organize components on to the window.
  • Frame: it is a window, it has title and icons
  • Dialog: it is like a pop-up window, used to display messages, it is also not a fully functional window like frame.

Java Layout Manager

Java Layout managers arrange the components inside a container. Several inbuilt layouts are defined in Java, but the most frequently used are:

  • BorderLayout: is a default layout for JFrame container, it divided frame into five parts: NORTH, SOUTH, EAST, WEST, CENTER.
  • FlowLayout: is a default layout for JPanel container, it arranges components row by row, staring from left to right, top to bottom, like we write in a page.
  • GridBadLayout: It arranges components by placing them in grid of cells; components can span more than one cell.
  • GridLayout: is used to create rows and columns like table in the container, components are placed in the cell of row and column intersection.