Java-Swing

Swing The Swing package in Java enables the programmers to create Graphical User Interface applications. It contains a number of classes that help to implement Windows-based tasks, such as manipulating windows, adding scroll bars, buttons, list items, text boxes, etc. All the classes are contained in the javax.swing package. These classes are hierarchically arranged inside … Read more…

extends JFrame

The JFrame is a class like any other and can be extended. Program       Program Source import javax.swing.JFrame; class Frame extends JFrame{ Frame() { setTitle(“First java GUI application”); setSize(700, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } public class Javaapp { public static void main(String[] args) { Frame frame = new Frame(); } }

JFrame with JLabel

JLabel is the Swing component that creates a label, which is a component that displays information. The label is Swing’s simplest component because it is passive. That is, a label does not respond to user input. It just displays output. The program uses a JFrame container to hold an instance of a JLabel. The label … Read more…

JFrame with FlowLayout

The FlowLayout arrange the components from the upper left corner, left to right and top to bottom. When no more components fit on a line, the next one appears on the next line. A small space is left between every components on each side. Program        Program Source import javax.swing.JFrame; import javax.swing.JLabel; import … Read more…

JLabel with ImageIcon

The swing icons are encapsulated by ImageIcon class. This class paints an image from the image. ImageIcon(String filename) Program       Program Source import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.ImageIcon; import java.awt.FlowLayout; class Frame extends JFrame{ Frame() { setTitle(“ImageIcon”); setLayout(new FlowLayout()); setLabel(); setSize(700, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setLabel() { ImageIcon icon = new … Read more…

setToolTipText

setToolTipText() :  SpecifIc text will be displayed when the mouse will pass over Swing Components. Program       Program Source import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.FlowLayout; class Frame extends JFrame{ Frame() { setTitle(“setToolTipText”); setLayout(new FlowLayout()); setLabel(); setSize(700, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setLabel() { JLabel jl = new JLabel(“JLabel”); jl.setToolTipText(“This is JLabel”); add(jl); … Read more…