Skip to main content

Posts

Showing posts from January 29, 2018

Swing JLabel demo with example

This article is continuation of previous post JFrame usage demo . Please read it before continuing. This post uses the same example code shown in  JFrame usage demo  with JLabel changes and introduces layout manager BorderLayout. Layout Manager: Layout manager is responsible to arrange components on containers. Usually every swing container is created with a default layout manager but can be changed with setLayout() api. For example JFrame uses BorderLayout as default layout amanger. Java program for JLabel 1  2   import java.awt.BorderLayout; 3   import java.awt.Color; 4   import java.awt.Font; 5  6   import javax.swing.JFrame; 7   import javax.swing.JLabel; 8   import javax.swing.SwingUtilities; 9  10  /** 11   * 12   * Simple class to demonstrate JLabel of swing toolkit 13   * 14   * @author Nagasharath 15   * 16  ...

Swing: JFrame usage demo

This post helps in understanding usage of JFrame class with an example Swing toolkit categorizes components into 2 types. They are: Containers Controls Containers allows Controls to be arranged on them. JPanel, JFrame and JDialog are few which are frequently used. Controls are components like Buttons, labels, tables etc. These controls are arranged on containers using different layout managers. All Swing class names starts with J stands for J ava which symbolizes swing is pure java!   Layout Managers: Layout manager is responsible for laying out controls on containers according to the business requirement. Example layout managers are BorderLayout, GridLayout, GridBagLayout and FlowLayout. Few points about JFrame: JFrame is considered as a main window of the application.for almost all swing based applications All other controls and containers are created as child components of JFrame JFrama holds special components like  Menu bar, Tool bar etc...