Javatpoint Logo

Java Swing Apps

Layoutmanagers.

JavaTpoint

is a part of Java Foundation Classes (JFC) that is . It is built on the top of AWT (Abstract Windowing Toolkit) API and entirely written in java.

Unlike AWT, Java Swing provides platform-independent and lightweight components.

The javax.swing package provides classes for java swing API such as JButton, JTextField, JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser etc.

There are many differences between java awt and swing that are given below.

No.Java AWTJava Swing
1)AWT components are .Java swing components are .
2)AWT components are .Swing components are .
3)AWT .Swing .
4)AWT provides than Swing.Swing provides such as tables, lists, scrollpanes, colorchooser, tabbedpane etc.
5)AWT (Model View Controller) where model represents data, view represents presentation and controller acts as an interface between model and view.Swing .

What is JFC

The Java Foundation Classes (JFC) are a set of GUI components which simplify the development of desktop applications.

  • How to create runnable jar file in java?
  • How to display image on a button in swing?
  • How to change the component color by choosing a color from ColorChooser ?
  • How to display the digital watch in swing tutorial ?
  • How to create a notepad in swing?
  • How to create puzzle game and pic puzzle game in swing ?
  • How to create tic tac toe game in swing ?

Hierarchy of Java Swing classes

The hierarchy of java swing API is given below.

hierarchy of javax swing

Commonly used Methods of Component class

The methods of Component class are widely used in java swing that are given below.

MethodDescription
public void add(Component c)add a component on another component.
public void setSize(int width,int height)sets size of the component.
public void setLayout(LayoutManager m)sets the layout manager for the component.
public void setVisible(boolean b)sets the visibility of the component. It is by default false.

Java Swing Examples

There are two ways to create a frame:

  • By creating the object of Frame class (association)
  • By extending Frame class (inheritance)

We can write the code of swing inside the main(), constructor or any other method.

Simple Java Swing Example

Let's see a simple swing example where we are creating one button and adding it on the JFrame object inside the main() method.

File: FirstSwingExample.java

simple example of java swing

Example of Swing by Association inside constructor

We can also write all the codes of creating JFrame, JButton and method call inside the java constructor.

File: Simple.java

The setBounds(int xaxis, int yaxis, int width, int height)is used in the above example that sets the position of the button.

Simple example of Swing by inheritance

We can also inherit the JFrame class, so there is no need to create the instance of JFrame class explicitly.

File: Simple2.java

  • JButton class
  • JRadioButton class
  • JTextArea class
  • JComboBox class
  • JTable class
  • JColorChooser class
  • JProgressBar class
  • JSlider class
  • Digital Watch
  • Graphics in swing
  • Displaying image
  • Edit menu code for Notepad
  • OpenDialog Box
  • Puzzle Game
  • Pic Puzzle Game
  • Tic Tac Toe Game
  • BorderLayout

Youtube

  • Send your Feedback to [email protected]

Help Others, Please Share

facebook

Learn Latest Tutorials

Splunk tutorial

Transact-SQL

Tumblr tutorial

Reinforcement Learning

R Programming tutorial

R Programming

RxJS tutorial

React Native

Python Design Patterns

Python Design Patterns

Python Pillow tutorial

Python Pillow

Python Turtle tutorial

Python Turtle

Keras tutorial

Preparation

Aptitude

Verbal Ability

Interview Questions

Interview Questions

Company Interview Questions

Company Questions

Trending Technologies

Artificial Intelligence

Artificial Intelligence

AWS Tutorial

Cloud Computing

Hadoop tutorial

Data Science

Angular 7 Tutorial

Machine Learning

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures

DAA tutorial

Operating System

Computer Network tutorial

Computer Network

Compiler Design tutorial

Compiler Design

Computer Organization and Architecture

Computer Organization

Discrete Mathematics Tutorial

Discrete Mathematics

Ethical Hacking

Ethical Hacking

Computer Graphics Tutorial

Computer Graphics

Software Engineering

Software Engineering

html tutorial

Web Technology

Cyber Security tutorial

Cyber Security

Automata Tutorial

C Programming

C++ tutorial

Control System

Data Mining Tutorial

Data Mining

Data Warehouse Tutorial

Data Warehouse

RSS Feed

  • Java Arrays
  • Java Strings
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Spring Boot

Introduction to Java Swing

Swing is a Java Foundation Classes [JFC] library and an extension of the Abstract Window Toolkit [AWT]. Java Swing offers much-improved functionality over AWT, new components, expanded components features, and excellent event handling with drag-and-drop support.

Introduction of Java Swing

Swing has about four times the number of User Interface [UI] components as AWT and is part of the standard Java distribution. By today’s application GUI requirements, AWT is a limited implementation, not quite capable of providing the components required for developing complex GUIs required in modern commercial applications. The AWT component set has quite a few bugs and does take up a lot of system resources when compared to equivalent Swing resources. Netscape introduced its Internet Foundation Classes [IFC] library for use with Java. Its Classes became very popular with programmers creating GUI’s for commercial applications.

  • Swing is a Set of API (API- Set of Classes and Interfaces)
  • Swing is Provided to Design Graphical User Interfaces
  • Swing is an Extension library to the AWT (Abstract Window Toolkit) 5:00 – 5:30 pm
  • Includes New and improved Components that have been enhancing the looks and Functionality of GUIs’
  • Swing can be used to build (Develop) The Standalone swing GUI Apps as Servlets and Applets
  • It Employs model/view design architecture.
  • Swing is more portable and more flexible than AWT, the Swing is built on top of the AWT.
  • Swing is Entirely written in Java.
  • Java Swing Components are Platform-independent, and The Swing Components are lightweight.
  • Swing Supports a Pluggable look and feel and Swing provides more powerful components.
  • such as tables, lists, Scrollpanes, Colourchooser, tabbed pane, etc.
  • Further Swing Follows MVC.

Difference between Java Swing and Java AWT

There are certain points from which Java Swing is different than Java AWT as mentioned below:

Java AWT

Java Swing

Java AWT is an API to develop GUI applications in Java.

Swing is a part of Java Foundation Classes and is used to create various applications.

Components of AWT are heavy weighted.

The components of Java Swing are lightweight.

Components are platform dependent.

Components are platform independent.

Execution Time is more than Swing.

Execution Time is less than AWT.

AWT components require java.awt package. 

Swing components requires javax.swing package.

To know more about the topic, refer to Java Swing vs Java AWT .

What is JFC?

JFC stands for Java Foundation Classes. JFC is the set of GUI components that simplify desktop Applications. Many programmers think that JFC and Swing are one and the same thing, but that is not so. JFC contains Swing [A UI component package] and quite a number of other items:

  • Cut and paste: Clipboard support.
  • Accessibility features: Aimed at developing GUIs for users with disabilities.
  • The Desktop Colors Features were first introduced in Java 1.1
  • Java 2D: it has Improved colors, images, and text support.

Features Of Swing Class  

  • Pluggable look and feel.
  • Uses MVC architecture.
  • Lightweight Components
  • Platform Independent
  • Advanced features such as JTable, JTabbedPane, JScollPane, etc.
  • Java is a platform-independent language and runs on any client machine, the GUI look and feel, owned and delivered by a platform-specific O/S, simply does not affect an application’s GUI constructed using Swing components.
  • Lightweight Components: Starting with the JDK 1.1, its AWT-supported lightweight component development. For a component to qualify as lightweight, it must not depend on any non-Java [O/s based) system classes. Swing components have their own view supported by Java’s look and feel classes.
  • Pluggable Look and Feel: This feature enable the user to switch the look and feel of Swing components without restarting an application. The Swing library supports components’ look and feels that remain the same across all platforms wherever the program runs. The Swing library provides an API that gives real flexibility in determining the look and feel of the GUI of an application
  • Highly customizable – Swing controls can be customized in a very easy way as visual appearance is independent of internal representation.
  • Rich controls – Swing provides a rich set of advanced controls like Tree TabbedPane, slider, colorpicker, and table controls.

Swing Classes Hierarchy

Swing Classes Hierarchy

The MVC Connection

  • The way that the component looks when rendered on the screen.
  • The way such that the component reacts to the user.
  • The state information associated with the component.
  • Over the years, one component architecture has proven itself to be exceptionally effective: – Model-View-Controller or MVC for short.
  • In MVC terminology, the model corresponds to the state information associated with the Component.
  • The view determines how the component is displayed on the screen, including any aspects of the view that are affected by the current state of the model.
  • The controller determines how the component reacts to the user.

The simplest Swing components have capabilities far beyond AWT components as follows: 

  • Swing buttons and labels can be displaying images instead of or in addition to text.
  • The borders around most Swing components can be changed easily. For example, it is easy to put a 1-pixel border around the outside of a Swing label.
  • Swing components do not have to be rectangular. Buttons, for example, can be round.
  • Now The Latest Assertive technologies such as screen readers can easily get information from Swing components. Example: A screen reader tool can easily capture the text that is displayed on a Swing button or label.

Example of Java Swing Programs

Example 1: develop a program using label (swing) to display the message “gfg web site click”:.

Java Swing to print message and click

Example 2: Write a program to create three buttons with caption OK, SUBMIT, CANCEL.

 

Add Buttons in the Frame

Example 3: Program to Add Checkbox in the Frame

Add Checkbox in the Frame

Components of Swing Class the task’s percentage

Class Description
Component A Component is the Abstract base class for about the non-menu user-interface controls of Java SWING. Components are representing an object with a graphical representation.
Container A Container is a component that can container Java SWING Components
JComponent A JComponent is a base class for all swing UI Components In order to use a swing component that inherits from JComponent, the component must be in a containment hierarchy whose root is a top-level Java Swing container.
JLabel A JLabel is an object component for placing text in a container.
JButton This class creates a labeled button.
JColorChooser                   A JColorChooser provides a pane of controls designed to allow the user to manipulate and select a color.
JCheckBox A JCheckBox is a graphical (GUI) component that can be in either an on-(true) or off-(false) state.
JRadioButton The JRadioButton class is a graphical (GUI) component that can be in either an on-(true) or off-(false) state. in the group
JList A JList component represents the user with the scrolling list of text items.
JComboBox A JComboBox component is Presents the User with a show up Menu of choices.
JTextField A JTextField object is a text component that will allow for the editing of a single line of text. 
JPasswordField                   A JPasswordField object it is a text component specialized for password entry.
JTextArea A JTextArea object is a text component that allows for the editing of multiple lines of text.
Imagelcon A ImageIcon control is an implementation of the Icon interface that paints Icons from Images
JScrollbar A JScrollbar control represents a scroll bar component in order to enable users to Select from range values.
JOptionPane     JOptionPane provides set of standard dialog boxes that prompt users for a value or Something.
JFileChooser   A JFileChooser it Controls represents a dialog window from which the user can select a file.
JProgressBar                As the task progresses towards completion, the progress bar displays the tasks percentage on its completion.
JSlider  A JSlider this class is letting the user graphically (GUI) select by using a value by sliding a knob within a bounded interval.
JSpinner  A JSpinner this class is a single line input where the field that lets the user select by using a number or an object value from an ordered sequence.

Please Login to comment...

Similar reads, improve your coding skills with practice.

 alt=

What kind of Experience do you want to share?

SlidePlayer

  • My presentations

Auth with social network:

Download presentation

We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!

Presentation is loading. Please wait.

Java Swing.

Published by Jessie Ellis Modified over 6 years ago

Similar presentations

Presentation on theme: "Java Swing."— Presentation transcript:

Java Swing

Introduction to Java 2 Programming

presentation on java swing

Introduction to Swing Components Chapter 14. Part of the Java Foundation Classes (JFC) Provides a rich set of GUI components Used to create a Java program.

presentation on java swing

Graphical User Interfaces

presentation on java swing

Java Software Development Paradigm Lecture # 12. Basics of GUI.

presentation on java swing

CS18000: Problem Solving and Object-Oriented Programming.

presentation on java swing

Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.

presentation on java swing

Graphic User Interfaces Layout Managers Event Handling.

presentation on java swing

CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.

presentation on java swing

Corresponds with Chapter 12

presentation on java swing

Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.

presentation on java swing

Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.

presentation on java swing

Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.

presentation on java swing

Swinging Into Swing Leo S. Primero III. Understanding what Swing Is Swing is a package that lets you create applications that use a flashy Graphical User.

presentation on java swing

Swing Components III Chapter 12 - Student JFrame, Component Methods.

presentation on java swing

CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.

presentation on java swing

Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.

presentation on java swing

Unit 11 Object-oriented programming: Graphical user interface Jin Sa.

presentation on java swing

Contructing GUI’s in Java Implemented in the Swing API Imported into your programs by: import javax.swing.*; Most Swing programs also need the AWT packages.

presentation on java swing

Java Swing Chris North cs3724: HCI. AWT to Swing AWT: Abstract Windowing Toolkit import java.awt.* Swing: new with Java2 import javax.swing.* Extends.

presentation on java swing

PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.

About project

© 2024 SlidePlayer.com Inc. All rights reserved.

Software Testing Help

Java SWING Tutorial: Container, Components and Event Handling

presentation on java swing

This comprehensive Java Swing video tutorial explains various components of the GUI Swing Framework and related concepts like JPanel, JFrame, JButton, etc:

We use graphical user interfaces (commonly called GUI) to build applications that have a visual interface by making it easy for the user to use the application.

Having a visual interface for an application makes the application easy to navigate, use controls more efficiently, and also it is visually appealing to the user.

Swing is mainly used for creating the GUI for applications.

=> Visit Here To See The Java Training Series For All.

Java SWING

Table of Contents:

Video Tutorial On Java Swing

What is java swing, java swing components, jframe in java, jpanel in java, jtextarea in java, jbutton in java, jlist in java, jcombobox in java, jslider in java, event handling in java, actionlistener in java, keylistener in java, swing layouts in java, flowlayout in java, gridlayout in java, setbounds in java, frequently asked questions, more about java swing, was this helpful, recommended reading.

Java provides many GUI frameworks that help us in developing a variety of GUI applications. We have seen one in our previous tutorial i.e. Abstract Window Toolkit or AWT. AWT is one of the oldest GUI frameworks in Java and is also platform dependent. Another disadvantage of AWT is its heavyweight components.

In this tutorial, we will discuss yet another GUI framework in Java i.e. “SWING”. The Swing framework in Java is a part of Java Foundation Classes or commonly called JFCs. JFC is an API that is similar to MFCs (Microsoft Foundation Classes) in C++. JFC contains Swing, AWT, and Java2D.

The Swing framework in Java is built on top of the AWT framework and can be used to create GUI applications just like AWT. But unlike AWT, the Swing components are light-weight and are platform-independent.

The Swing framework is written entirely in Java. The Swing framework in Java is provided through the ‘javax.swing’ package. The classes in the javax.swing package begins with the letter ‘J’. So in a javax.swing package, we will have classes like JButton, JFrame, JTextField, JTextArea, etc.

In general, the Swing API has every control defined in javax.swing package that is present in AWT. So swing in a way acts as a replacement of AWT. Also, Swing has various advanced component tabbed panes. Swing API in Java adapts MVC (Model View Controller) Architecture.

The main characteristics of this architecture are:

  • The swing component’s data is represented using Model.
  • It is visually represented using a view.
  • The controller component of the MVC architecture reads input from the user on the view and then these changes are passed to the component data.
  • In each Swing component, the view and controller are clubbed together while the model is a separate one. This gives swing a pluggable look and feel feature.

The features of the swing API are summarized below.

  • Swing components are platform-independent.
  • The API is extensible.
  • Swing components are light-weight. The swing components are written in pure Java and also components are rendered using Java code instead of underlying system calls.
  • Swing API provides a set of advanced controls like TabbedPane, Tree, Colorpicker, table controls, etc. which are rich in functionality.
  • The swing controls are highly customizable. This is because the appearance or look-and-feel of the component is independent of internal representation and hence we can customize it in the way we desire.
  • We can simply change the values and thus alter the look-and-feel at runtime.

Swing has a big set of components that we can include in our programs and avail the rich functionalities using which we can develop highly customized and efficient GUI applications.

So what is a component?

A component can be defined as a control that can be represented visually and is usually independent. It has got a specific functionality and is represented as an individual class in Swing API.

For example, class JButton in swing API is a button component and provides the functionality of a button.

One or more components form a group and this group can be placed in a “Container”. A container provides a space in which we can display components and also manage their spacing, layout, etc.

In Java, Containers are divided into two types as shown below:

Container Types

Swing Classes In Java

A Swing API hierarchy in Java is shown below:

Introduction to Swing Classes

As seen from the above hierarchy we have Container classes – frame, dialog, Panel, Applet, etc. There are also Component classes derived from the JComponent class of Swing API. Some of the classes that inherit from JComponent are JLabel, JList, JTextBox, etc.

Some of the important classes of Swing API are as follows:

  • JWindow: The JWindow class of Swing inherits the Window class directly. The JWindow class uses ‘BorderLayout’ as the default layout.
  • JPanel:  JPanel is a descendent of JComponent class and is on similar lines to AWT class Panel and has ‘FlowLayout’ as the default layout.
  • JFrame: JFrame descends from the Frame class. The components added to the Frame are called contents of the Frame.
  • JLabel: JLabel class is a subclass of the JComponent. It is used to create text labels in the application.
  • JButton: The push-button functionality in Swing is provided by JButton. We can associate a string, an icon, or both with the JButton object.
  • JTextField: JTextField class provides a text field in which we can edit a single line of text.

A Frame, in general, is a container that can contain other components such as buttons, labels, text fields, etc. A Frame window can contain a title, a border, and also menus, text fields, buttons, and other components. An application should contain a frame so that we can add components inside it.

The Frame in Java Swing is defined in class javax.swing.JFrame. JFrame class inherits the java.awt.Frame class. JFrame is like the main window of the GUI application using swing.

We can create a JFrame window object using two approaches:

#1) By Extending The JFrame Class

The first approach is creating a new class to construct a Frame. This class inherits from the JFrame class of the javax.swing package.

The following program implements this approach.

By extending the JFrame class

#2) By Instantiating The JFrame Class

By instantiating JFrame class

In the above program, we have created a frame from the JFrame class by creating an instance of the JFrame class.

A panel is a component that is contained inside a frame window. A frame can have more than one-panel components inside it with each panel component having several other components.

In easier terms, we can use panels to partition the frame. Each panel groups several other components inside it. In other words, we use panels to organize components inside the frame.

The swing API class that implements the panel component is JPanel. JPanel class inherits from JComponent and has FlowLayout as its default layout.

The following program demonstrates the creation of a panel container in a frame using javax.swing package classes.

JPanel in Java

Here we have a Frame. Inside the frame, we create a panel. Then inside the panel, we create a button. This way we can use a panel to hold the other components.

TextArea defines an editable text field. It can have multiple lines. The swing class that defines the text area is JTextArea and it inherits the JTextComponent class.

public class JTextArea extends JTextComponent

JTextArea class contains 4 constructors that allow us to create a text area with various options.

  • JTextArea (): Default constructor. Create an empty text area.
  • JTextArea (String s): Creates a textarea with s as the default value.
  •  JTextArea (int row, int column): Creates a text area with a specified row x column.
  • JTextArea (String s, int row, int column): Creates a text are2a with specified row x column and default value s.

The following Java program shows an example of the JTextArea component in the swing.

JTextArea in Java

A button is a component that is used to create a push button with a name or label on it. In swing, the class that creates a labeled button is JButton. JButton inherits the AbstractButton class. We can associate the ActionListener event to the button to make it take some action when it is pushed.

Let’s implement an example program for JButton in Java swings.

JButton in Java

A list consists of multiple text items. Users can either select a single item or multiple items at a time. The class that implements the list in swing API is JList. JList is a descendent of the JComponent class.

Given below are the constructors of the JList class.

  • JList (): Default constructor that creates an empty, read-only list.
  • JList (array[] listItem): Create a JList which initially contains elements of array listItem.
  • JList (ListModel<array> dataModel): Creates a list with elements from the specified model dataModel.

A simple demonstration of the JList component is given below.

JList in Java

In the above program, we first define a listModel with color entries in it. Then we create a JList object and add the listModel to it. Next, the JList object is added to the frame object which is then displayed.

The JCombobox class shows a list of choices from which a user can select an option. The selected choice is at the top. JComboBox derives from the JComponent class.

The following are the constructors provided by JComboBox class:

  • JComboBox (): Default constructor that creates a ComboBox with the default data model.
  • JComboBox (Object[] items): This constructor creates a ComboBox having items as elements of the given array items.
  • JComboBox (Vector<?> items): This constructor reads the elements of the given vector and constructs a ComboBox with these elements as its items.

JComboBox class also provides methods to add/remove items, add ActionListener, ItemListener, etc.

The following example demonstrates the JComboBox implementation in Java.

JComboBox implementation

A slider allows us to select a specific range of values. In Java Swing API, JSlider is the class that is used to implement the slider.

The following are the constructors provided by JSlider class.

  • JSlider (): A default constructor that creates a slider having 50 as the initial value and range 0 -100.
  • JSlider (int orientation): This constructor creates a slider just like above but with a specified orientation. Orientation value can be either JSlider.HORIZONTAL or JSlider.VERTICAL.
  • JSlider (int min, int max): This constructor is used to create a horizontal slider using the given min and max.
  • JSlider (int min, int max, int value): This constructor creates a slider that is horizontal with the specified value of min, max, and value.
  • JSlider (int orientation, int min, int max, int value): This constructor constructs a slider with specified orientation, min, max, and value.

The following program demonstrates the JSlider in Java with ticks. This program also demonstrates the usage of the methods supported by the JSlider class.

JSlider in Java

An event can be defined as a change of state of an object. From the GUI point of view, an event occurs when the end-user interacts with the GUI components. The events that get triggered in the GUI can be the click of a button, scrolling, selecting list items, changing text, etc.

Event occurring in the GUI listed above are mostly foreground events. We can also have some background events like background operation completion, timer expiration, etc.

Event handling is a mechanism through which an action is taken when an event occurs. For this, we define a method which is also called an event handler that is called when an event occurs. Java uses a standard mechanism called the “Delegation event model” to generate as well as handle events.

The Delegation event model consists of:

#1) Source: The Source of the event is the object. The object on which an event occurs is the source and the source is responsible for sending information about the event to the event handler.

#2) Listener: The listener is nothing but the event handler responsible for taking an action when an event occurs. In Java, a listener is an object that waits on an event. Once the event occurs, the listener processes the event.

The requirement is to register the listener with the object so that when an event occurs, the listener can process it.

For example, for a button click event, we can have the following sequence of steps.

  • The user clicks the button that generates a Click event.
  • The appropriate event class object is created and the source and event data are passed to this object.
  • This event object is then passed to the listener class registered with the object.
  • The listener executes and returns.

Now let’s discuss some of the listeners provided by Java.

An actionListener is the listener for a button or a menu item. When we click on a button, the button Listener that is involved is the actionListener. The actionListener is notified in the ActionEvent.

The java.awt.an event package defines the ActionListener interface. This interface has only one method actionPerformed ().

public abstract void actionPerformed (ActionEvent e);

When a registered component like a Button is clicked, then the actionPerformed () method is automatically invoked.

The most common approach to include ActionListener in the program is to implement the ActionListener interface and then implement the actionPerformed () method.

The steps to implement ActionListener class are as follows:

#1) Implement the interface ActionListerner.

public class ActionListenerImpl Implements ActionListener

#2) Register the component with this listener. If the button is a component that we want to register with the listener then we will register it as follows:

button.addActionListener (instanceOfListenerclass);

#3) Implement/override the actionPerformed () method.

So using the above steps, we can associate any event with the GUI component.

The following example demonstrates a button Click event using ActionListener.

ActionListener in Java

The above program implements an ActionListener event. The event is the Button click event and with it, we have associated an ActionListener that displays the text in the text field on clicking the button.

Whenever there is a change in the state of the key, a KeyListener is notified. Just like ActionListener, the KeyListener is also found in the java.awt.event package.

KeyListener interface provides the following methods:

public abstract void keyPressed (KeyEvent e);

public abstract void keyReleased(KeyEvent e);

public abstract void keyTyped(KeyEvent e);

We need to implement the above methods to associate the key events with the component. We leave it to the user to implement a KeyListener example using swings in Java.

When we arrange various components in a container, then we say we are laying out those components. So a layout can be defined as the positioning of components in a container.

As long as there are fewer components, they can be placed by drag-drop manually. But it becomes difficult to arrange the components large in numbers. At this juncture, the Layout Manager of Java comes to our aid.

LayoutManager is responsible for the components’ layout in GUI applications. LayoutManager is an interface and it is implemented by all the layout manager classes. Java provides the following LayoutManager classes.

LayoutManagerDescription
java.awt.BorderLayoutComponents are laid out to fit in five directions namely center, east, west, south, north.
java.awt.FlowLayoutThis is the default layout. It lays the components in the directional flow.
java.awt.GridLayoutArranges the components in a rectangular grid.
javax.swing.BoxLayoutComponents are arranged in a box.
java.awt.CardLayoutEach component is viewed as a card in a deck and at a time only one component is visible.
java.awt.GridBagLayoutArranges components vertically, horizontally, or even along their baselines. Components need not be of the same size.
javax.swing.GroupLayoutGroups the components and then positions them in the container.
javax.swing.ScrollPaneLayoutUsed by JScrollPane class and is responsible for arranging components in scrollable containers.
javax.swing.SpringLayout etc.A set of constraints like the horizontal and vertical distance between components etc. is provided and the components are arranged according to these set of constraints.

In this tutorial, we will only discuss FlowLayout and GridLayout.

The FlowLayout arranges the components in a flow direction, one after another. This is the default layout for the containers like Panel and Applet.

The FlowLayout class in Java that represents the FlowLayout manager contains the following Fields and constructors.

Fields Of FlowLayout Class

  • public static final int LEADING
  • public static final int TRAILING
  • public static final int LEFT
  • public static final int RIGHT
  • public static final int CENTER

The above fields define the positions at which the components will be placed or aligned.

Constructors Of FlowLayout Class

  • FlowLayout (): This is a default constructor. This constructor creates a flow layout having centrally aligned components with a default gap of 5 units in the horizontal and vertical direction.
  • FlowLayout (int align): This constructor creates a flow layout with the specified alignment value and with a horizontal and vertical gap of 5 units.
  • FlowLayout (int align, int hgap, int vgap): Creates a flow layout with specified alignment value and horizontal and vertical gap.

Given below is an example of FlowLayout in Java.

Constructors of FlowLayout class

Using GridLayout we can layout the components in a rectangular grid fashion i.e. each component is arranged in each rectangle.

Constructors Of GridLayout Class

  • GridLayout ():  default constructor that generates a grid layout having one column per one component in a row.
  • GridLayout (int rows, int columns): This constructor generates a grid layout with specified rows and columns. There is no gap between the components.
  • GridLayout (int rows, int columns, int hgap, int vgap): Using this constructor, we generate a grid layout with specified rows and columns and horizontal and vertical gaps.

The following example implements the GridLayout in Java.

GridLayout in Java

If we check the programming examples in this tutorial before the layout topic, we can see that we have set the layout as null in these examples (setLayout(null)). We have seen that when we use layout managers in our program, they automatically position the components.

When layout managers are not used, we can use the setBounds method to the size and position of the component. So the method setBounds is used to manually position the component and also set the size.

The general syntax of the setBounds method is as follows:

setBounds (int x-coordinate, int y – coordinate, int width, int height)

Let’s now implement an example of the SetBounds method.

Setbounds in Java

In the above program, we have a Button component. We have not set any layout but we have used the setBounds method to set its position and dimensions.

Swing Vs JavaFX

SwingJavaFX
Swing provides an API to create GUI components. JavaFX provides scripts and fast UI development associated with screen builder.
There is going to be no new functionality added to Swing in future versions.JavaFX provides rich functionality and has the potential for more features in future versions.
We can create all standard components using Swing API.JavaFX allows us to create rich GUI components using advanced look and feel.
A large number of components are present in Swing.JavaFX has a comparatively lesser number of components.
Swing is a fully-features UI library.JavaFX is a new and upcoming API with rich UI components.
Swing has loose MVC support. JavaFX supports MVC pattern consistently.

Q #1) Is Swing still used in Java?

Answer: Yes, Swing is still being used in Java and that too heavily. Sometimes it is used as a complete replacement for AWT. Sometimes it is also used along with some of the AWT components. It is even used with the latest JavaFX. So Swing is still used and will be used for a long time to come.

Q #2) How does Java Swing work?

Answer: Swing in Java is written on top of the AWT framework. So the event handling of AWT is inherited by swing completely. Swing also provides a large number of components that we can use to develop efficient GUI applications.

Q #3) Does Swing follow MVC?

Answer: Swing API has loose MVC support. The model represents the data of the component. The swing component has a separate element called Model whereas Controller and View are clubbed together in UI elements. This clubbing allows the swing to have a pluggable look and feel.

Q #4) Is JavaFX better than Swing?

Answer: Swing has been around for a long time and has more mature IDE support. It also had a very big library of components. JavaFX is comparatively newer and has a small library of components but with more consistent updates and consistent MVC support. Thus it depends on how JavaFX develops further and provides more features.

Q #5) Which is better AWT or Swing?

Answer: Swing is built on top of AWT and provides a rich and large set of UI components when compared to AWT. Swing components also can have their look and feel as against AWT components that take a look and feel of the Operating system.

Swing components are faster than AWT. All these factors make the swing better than AWT.

When you create an application, initially you should have a base container and you have to add the required components like buttons and text fields in the container.

And when you click or perform any operation on any field, the event will occur and your code should listen to the events and also handle the event.

Swing Container

A container is a root element for an Application. All the other components are added to that root and it forms a hierarchy.

There are three container classes:

Container Demo using JFrame:

Container Demo using JFrame

When you run the above program, you will get the below output.

base container

JComponent class is a base class for all the components in a swing.

The frequently used components include,

  • JRadioButton
  • JComboBox etc.

All these components should be added to the container if not, it will not appear on the application.

To create the button instance,

JButton clickButton=new JButton();

To add the button to the container,

myFrame.add();

Event Handling

All the Applications are driven by events like button clicks, mouse clicks, user text input etc. When the event occurs, you have to add a listener and must pass the source event object.

With an inner class, you can handle the event with your logic as shown below.

Event Handling

In this tutorial, we have touched base with the Swing API provided by Java for building GUI applications. We have discussed the major swing containers and components and their implementation.

We have also discussed event handling in Swing. Although the event handling mechanism is of AWT, swing implements the events in an efficient manner. Then we discussed the various layout managers provided by Swing API that allow us to layout or arrange various components in the Swing GUI applications.

  • Java Reflection Tutorial With Examples
  • JAVA Tutorial For Beginners: 100+ Hands-on Java Video Tutorials
  • Java Collections Framework (JCF) Tutorial
  • Access Modifiers In Java - Tutorial With Examples
  • Java String Data Type With String Buffer And String Builder
  • Introduction To Java Programming Language - Video Tutorial

Leave a Comment Cancel reply

  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

Java Swing and Presentation Model

I am developing an application in Java and I am using Swing for GUI. I was going to do it using Presentation Model pattern which is introduced by Martin Fowler here: http://martinfowler.com/eaaDev/PresentationModel.html

but I really don't like when I have to deal with View within my Presentation Model class so I figure out I can do it differently.

In my approach I will have a CustomViewModel class extending Swing component model ( like TableModel for JTable or ButtonModel for JButton). This class will override method that is executed when user updates data on model. So I will do my job like updating DomainModel and then calling parents method. This way I will have data always in sync between DomainModel and ViewModel.

For Example:

in setup gui function I would have:

So now in my Controller function I can have:

And that's it MyCustomTableModel has overriden method that is used by JTable to update it's content and having my code before the actual call to parents setModel I am updating actual Model. No need for view reference. The problem is when I need to deal with JFileChooser which don't have similar relationship as rest of components. I am talking about some ViewModel class.

Does anyone have an idea how to tacle this approach.

What I am trying to achieve is not to have reference to View in both MyCustomComponentModel and Controller. I would like to make the comunication between controller and view via set of CustomComponentModel which extends view models like TableModel, ButtonModel etc. The purpose of that is easier TDD. In this approach only Layout of things is not tested.

  • presentation-model

mKorbel's user avatar

  • put any Items to util.List (by default required AbstractTableModel) or if Item returns Vector that you can to use, override DeafultTableModel, another issue will be (care about) lifecycle from underlaying array (Item) to Model –  mKorbel Commented Oct 9, 2013 at 7:24
  • deal with View within my Presentation Model that's definitely not what Fowler suggests, so you are misunderstanding the articles somewhere. So you are wasting your time in solving a "problem" that you introduced yourself ;-) –  kleopatra Commented Oct 9, 2013 at 10:06
  • @kleopatra Fowler suggests in his article that either Presentation Model or View should deal with synchronization and there are two ways to do that. One is to have view reference in your Presentation Model which is better from TDD perspective. The Second one is to have View dealing with synchronization and that is something worse from TDD perspective. So what I am trying to achieve is to figure out a way of not having to deal with View mocks in my tests :) And if I can wrap component model in a class and comunicate with view via it I would achieve my goal. –  user2861410 Commented Oct 10, 2013 at 6:44
  • be careful: the synch Fowler is talking about is the synch between PresentationModel and View (vs. between pm and domain/backend) And that's handled easily via standard mechanisms (plain beans or a binding framework like BeansBinding or JGoodies Binding), so testing of such synch can (mostly) rely on the binding framework having been tested extensively plus some trivialites that the bindings are indeed in place. –  kleopatra Commented Oct 10, 2013 at 10:00
  • if you are interested, My swingx incubator has examples (untested <g>) of my usual setup, using Fowler's example. –  kleopatra Commented Oct 10, 2013 at 10:01

Know someone who can answer? Share a link to this question via email , Twitter , or Facebook .

Your answer.

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Browse other questions tagged java swing jtable tablemodel presentation-model or ask your own question .

  • Featured on Meta
  • We spent a sprint addressing your requests — here’s how it went
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network...
  • Policy: Generative AI (e.g., ChatGPT) is banned
  • The [lib] tag is being burninated
  • What makes a homepage useful for logged-in users

Hot Network Questions

  • add an apostrophe to equation number having a distant scope
  • Are there examples of triple entendres in English?
  • How do I prevent losing the binoculars?
  • Event sourcing javascript implementation
  • Is arxiv strictly for new stuff?
  • Correlation for Small Dataset?
  • Con permiso to enter your own house?
  • Can front gear be replaced on a Retrospec Judd folding bicycle?
  • Verify that a quadratic form is NOT positive definite
  • I want to remove the console display that appears when reloading a script
  • What is the translation of misgendering in French?
  • Why should I meet my advisor even if I have nothing to report?
  • What is a positive coinductive type and why are they so bad?
  • Is there a drawback to using Heart's blood rote repeatedly?
  • Bug in scene camera?
  • Why should the Vce be half the value of the supply source?
  • How do I find the order of the subgroup in a Diffie-Hellman key exchange?
  • How can I augment a 1D tablar dataset using an additional 2D dataset?
  • Can I get a refund for ICE due to cancelled regional bus service?
  • Was BCD a limiting factor on 6502 speed?
  • Summation not returning a timely result
  • Can you help me to identify the aircraft in a 1920s photograph?
  • Wiring the output of a D flip-flop to its input
  • What are these courtesy names and given names? - confusion in translation

presentation on java swing

java swing events

Java Swing, Events

Mar 27, 2012

430 likes | 848 Views

Java Swing, Events. Readings: Just Java 2 : Chap 19 &amp; 21, or Eckel’s Thinking in Java : Chap 14 Slide credits to CMPUT 301, Department of Computing Science University of Alberta. Java Foundation Classes. JFC: Abstract Window Toolkit (AWT) original user interface toolkit don’t go there!

Share Presentation

  • uml sequence diagram
  • containment hierarchy
  • different event sources
  • theframe getcontentpane

nikita

Presentation Transcript

Java Swing, Events Readings: Just Java 2: Chap 19 & 21, or Eckel’s Thinking in Java: Chap 14 Slide credits to CMPUT 301, Department of Computing Science University of Alberta

Java Foundation Classes • JFC: • Abstract Window Toolkit (AWT) • original user interface toolkit • don’t go there! • Swing • package javax.swing.*, introduced in Java 1.2

Swing • Portable API: • The appearance and behavior (look-and-feel) of the user interface components are implemented in Java … • might work slightly differently from any host platform • pluggable look-and-feelse.g., Motif, windows,…

Containment Hierarchy • Top-level container: • place for other Swing components to paint themselves • e.g., JFrame, JDialog, Japplet • Intermediate container: • simplify positioning of atomic components • e.g., JPanel, JSplitPane, JTabbedPane

Containment Hierarchy • Atomic components: • self-sufficient components that present information to and get input from the user • e.g., JButton, JLabel, JComboBox, JTextField, JTable

Swing • Componentsand containers: • superclassesand interfaces • extendsand implements © O’Reilly 1999

Swing • Java Documentation: • http://java.sun.com/j2se/1.4.1/docs/api/javax/swing/package-summary.html • SwingSet: • http://java.sun.com/products/javawebstart/demos.html • Quick tutorial: • http://java.sun.com/docs/books/tutorial/uiswing/start/swingTour.html

Containers • Notes: • Container objects group components, arranging them for display with a layout manager.

Top-Level Containers • JFrame example: • contains a single component JRootPane, which has a JMenuBar (optional) and a content pane • theFrame.setJMenuBar( theMenuBar ) • theFrame.setContentPane( thePanel ) • add non-menu components to this content pane • theFrame.getContentPane().add( aButton )

Events • Two approaches to event handling • read-evaluation loop (client-written loop) • notification-based (callbacks) • Swing uses the 2nd approach

Events • Swing: • objects communicate by “firing” and “handling” events (event objects) • (conventional method call) • events are sent from a single source object to one or more registered listener objects

Events • Swing: • different event sources produce different kinds of eventse.g., a JButton object, when clicked, generates an ActionEvent object, which is handled by an ActionListener (an object whose class implements this interface)

Events • Handling: • create a component • e.g., a JButton • add it to the GUI • e.g., to a JPanel • register a listener to be notified when the component generates an event • e.g., interface ActionListener • define the callback method • e.g., actionPerformed()

Event Handling • class MyListener implements ActionListener { … public void actionPerformed( ActionEvent event ) {// react to event … }} • …// instantiate event listenerActionListener listener = new MyListener();…// instantiate event sourceJButton button = new JButton( “Hello” );…// register event listener with event sourcebutton.addActionListener( listener );

UML Sequence Diagram

Event Handling • Options for implementing listeners: • listener class • anonymous inner classes • named inner classes

Event Handling • Listener class:

Event Handling • Anonymous inner listener class:

Event Handling • Named inner listener class:

Event Handling • Note: • A class could potentially be both an event source and event listener. • Good or bad idea? …

Event Handling • public class MyButton extends JButton implements ActionListener { … public MyButton() { … addActionListener( this ); } … public void actionPerformed( ActionEvent event ) { … }} • JButton button = new MyButton() …

Dependencies

Dependencies • Problems: • need to maintain consistency in the views (or observers) • need to update multiple views of the common data model (or subject) • need clear, separate responsibilities for presentation (look), interaction (feel), computation, persistence

Model/View/Controller • MVC roles: • model • complete, self-contained representation of object managed by the applicatione.g., spreadsheet document • provides a number of services to manipulate the datae.g., recalculate, save • computation and persistence issues • …

Model/View/Controller • MVC roles: • view • tracks what is needed for a particular perspective of the datae.g., bar chart view • presentation issues • controller • gets input from the user, and uses appropriate information from the view to modify the modele.g., get slider value, trigger chart modify • interaction issues

Model/View/Controller

Model/View/Controller • Separation: • you can modify or create views without affecting the underlying model • the model should not need to know about all the kinds of views and interaction styles available for it • separate threads?

Model/View/Controller • In Swing: • in practice, views and controllers are implemented with Swing components and listeners • both views and controllers will be dependent on Swing APIs

Model/View/Controller • In Swing: • still, try to separate the model and its services so that it is Swing-free • model is like a “virtual machine” or “kernel” specific to the application

Model/View/Controller • Smalltalk: • originated the MVC concept • integral support in interactive applications with MVC classes

Model/View/Controller • Java and Swing: • concept is still valid to help structure interactive applicationse.g., use a framework that supports MVC • Swing internally uses a variant of MVC for its pluggable look-and-feel capability …

Pluggable Look-and-Feel • Swing: • the look-and-feel is implemented in Java, but could mimic Windows, Motif, Classic, Aqua, etc. • UIManager.setLookAndFeel(“com.sun.java.swing.plaf.windows.WindowsLookAndFeel”); • UIManager.setLookAndFeel(“javax.swing.plaf.metal.MetalLookAndFeel”);

Pluggable Look-and-Feel • SwingSet: • http://java.sun.com/products/javawebstart/demos.html

Pluggable Look-and-Feel • Idea: • similar to skins, themes, schemes, etc., but must include “feel” as well as “look”

Pluggable Look-and-Feel • Swing internals: • each component uses a user interfacedelegate object (responsible for view and controller roles)

Pluggable Look-and-Feel • Swing internals: • each component specifies a model interface that an associated model class must implement

Model/View/Controller • CRC cards for MVC: • discuss what models, views, and controllers there are in the system • be a design critic

  • More by User

GUIs in Java Swing, Events

GUIs in Java Swing, Events

GUIs in Java Swing, Events. CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise. Why Study GUIs in CS2110. First, why not? Complex topic, complex library Many classes, methods Hard to do this well initially Reasons we study GUIs

238 views • 22 slides

Lec09 :: Java Swing

Lec09 :: Java Swing

Lec09 :: Java Swing. เรื่อง jOptionPane Nattapong Songneam http://www.siam2dev.com. AWT to Swing. AWT: Abstract Windowing Toolkit import java.awt.* Swing: new with Java2 import javax.swing.* Extends AWT Tons o’ new improved components Standard dialog boxes, tooltips, …

664 views • 48 slides

Java Swing

Java Swing. Introduction to Swing. A GUI (graphical user interface) is a windowing system that interacts with the user The Java AWT (Abstract Window Toolkit) package is the original Java package for doing GUIs The Swing package is an improved version of the AWT

1.58k views • 101 slides

JAVA GUI Swing

JAVA GUI Swing

JAVA GUI Swing. http://docs.oracle.com/javase/tutorial/uiswing/start/index.html. İlk Gui ( graphical User Interface ). İmports javax. Content Pane. http:// docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html. JComponent Class.

655 views • 32 slides

Java Swing

Java Swing. Chris North cs3724: HCI. AWT to Swing. AWT: Abstract Windowing Toolkit import java.awt.* Swing: new with Java2 import javax.swing.* Extends AWT Tons o’ new improved components Standard dialog boxes, tooltips, … Look-and-feel, skins Event listeners API:

470 views • 21 slides

Java Swing

Java Swing. Walter Milner. Note - this presentation. often needs to refer to source code which is too big to put on a slide So the source code is in a separate Word document And is also given in within this presentation in the notes. What is Swing?. A group of 14 packages to do with the UI

883 views • 58 slides

Java Swing

Java Swing. Walter Milner. What is Swing?. A group of 14 packages to do with the UI 451 classes as at 1.4 (!) Part of JFC Java Foundation Classes (compare now defunct MFC). Swing and the AWT. AWT = abstract windows toolkit (cross platform) AWT = earliest version of Java GUI

962 views • 54 slides

Java Swing Overview

Java Swing Overview

Java Swing Overview. O’Riordan, Nov., 2007 Includes notes by K. Brown, 2004-2007. What is Swing?. Swing widget toolkit for Java used for constructing a graphical user interface (GUI) - part of The Java Foundation Classes (JFC)

615 views • 32 slides

JAVA Swing 簡介

JAVA Swing 簡介

JAVA Swing 簡介. 鄧姚文 [email protected] http://www.ywdeng.idv.tw. What is Swing?. The Swing package is part of the Java Foundation Classes (JFC) JFC encompasses a group of features to help people build GUIs Swing provides all the components from buttons to split panes and tables.

620 views • 23 slides

Java Events

Java Events

Java Events. Overridden method: is an action that happens between a base(super) class and its child when they have the same method.

335 views • 21 slides

Java Swing Application Flow

Java Swing Application Flow

Java Swing Application Flow. By mr. Hanley 11/7/2005. How does a swing app flow?. In our Swing Applications, we have used two files, an app file and a frame file Let’s take the SnowFall Assignment as an Example. How does a swing app flow?. 1. A java application looks for a main method

278 views • 14 slides

Java Swing

Java Swing. The origins of the Swing The AWT components use native code resources and referred to as heavyweight. The native use of peers led to several problems

6.15k views • 116 slides

Java Swing

Java Swing. Joon Ho Cho. What is Java Swing?. Part of the Java Foundation Classes (JFC) Provides a rich set of GUI components Used to create a Java program with a graphical user interface (GUI) table controls, list controls, tree controls, buttons, and labels, and so on….

408 views • 20 slides

Java Swing

Java Swing. Swing is a set of classes that provides more powerful and flexible components than are possible with the AWT.

329 views • 18 slides

Java Swing, continued

Java Swing, continued

Java Swing, continued. Swing component hierarchy. Graphical components in Java form an inheritance hierarchy: java.lang.Object +-- java.awt.Component +-- java.awt.Container | +-- javax.swing.JComponent | +-- javax.swing. JButton

881 views • 72 slides

JAVA SWING

JAVA SWING. By Tahira Braschi April 20, 2001 Dr. Marchant CS 108-002. What is JFC?. JFC stands for Java Foundation Classes, and it includes a group of features to help people build GUIs (Graphical User Interfaces). Features which help defined JFC are: The Swing components

355 views • 26 slides

PowerShow.com - The best place to view and share online presentations

  • Preferences

Free template

JAVA SWING - PowerPoint PPT Presentation

presentation on java swing

JFC stands for Java Foundation Classes, and it includes a group of features to ... For example, if you get carpal tunnel syndrome, you can use assistive ... – PowerPoint PPT presentation

  • Tahira Braschi
  • April 20, 2001
  • Dr. Marchant
  • JFC stands for Java Foundation Classes, and it includes a group of features to help people build GUIs (Graphical User Interfaces).
  • Features which help defined JFC are
  • The Swing components
  • Pluggable Look and Feel Support
  • Accessibility API (Application Programmer Interface)
  • Java 2D API
  • Drag and Drop Support
  • Swing is the codename of the project that developed the new components. It is not the official name.
  • However, its frequently used to refer to the new components and related API.
  • Part of the Java Foundation Classes (JFC), and can be used with either JDK 1.1 or the Java 2 platform.
  • Include everything buttons, lists, menus, tables, text areas, and containers such as windows and tool bars.
  • Frameis a window that has decorations such as a border, a title, and buttons for closing and iconifying the window. Applications with a GUI typically use at least one frame.
  • Intermediate containers which can be used under many different circumstances
  • Scroll pane
  • Tabbed pane
  • Panelmost flexible and frequently used. Add almost no functionality beyond what all objects have. Often used to group components.
  • Scroll paneprovides scroll bars around a large or growable component.
  • Split panedisplays two components in a fixed amount of space, letting the user adjust the amount of space devoted to each component.
  • Tabbed panecontains multiple components but show only one at a time. The user can easily switch between components.
  • Tool barholds a group of components (usually buttons) in a row or column, optionally allowing the user to drag the tool bar into different locations.
  • Intermediate containers that play specific roles in the use interface.
  • Internal frame Able to display display a Frame-like window within another window. Usually, you add internal frames to a desktop pane.
  • Layered frameProvides a third dimension for positioning components depth, also known as Z order.
  • Root paneHas 4 parts glass pane, layered pane, content pane, and the (optional) menu bar.
  • Atomic components that exist primarily to get input from the user they generally also show simple state.
  • Buttonscan be square or round
  • Combo Boxcan be uneditable and editable.
  • ListPresents the user with a group of items, displayed in a column, to choose from.
  • Menuprovides a space-saving way to let the user choose one of several options.
  • Sliderlets user enter a numeric value bounded by a minimum and maximum value.
  • Text Fieldsbasic text control that lets the user enter a small amount of text.
  • Atomic components that exist solely to give the user information.
  • Labelable to display unselectable text and images.
  • Progress Bardisplays the progress of a long-running task (also, ProgressMonitor and ProgressMonitorInputStream)
  • Tool tipcomes up when the user of the program pauses with the cursor over any of the program's buttons
  • Atomic components that display highly formatted information that can be edited by the user.
  • Color chooserprovide users with a palette of colors to choose from.
  • File chooserprovide a GUI for navigating the file system, and then either choosing a file or directory from a list or entering a file name or directory name.
  • Tabledisplays tables of data, optionally allowing the user to edit the data.
  • Textdisplays text and allows user to edit it
  • Treedisplays data in hierarchical way
  • Gives any program that uses Swing components a choice of looks and feels. For example, the same program can use either the Java look-and-feel or the Windows look-and-feel.
  • Many more look-and-feel packages will be available in the future from various sources, including some that use sound instead of a visual look.
  • Enables assistive technologies such as screen readers and Braille displays (for blind people) to get information from the user interface.
  • Primarily, assistive technologies exist to enable people with permanent or temporary disabilities to use the computer.
  • For example, if you get carpal tunnel syndrome, you can use assistive technologies to accomplish your work without using your hands.
  • Enables developers to easily incorporate high-quality 2D graphics, text, and images in applications and in applets.
  • Enables you to display complex charts and graphs that use various line and fill styles to distinguish sets of data.
  • Enables you to store and to manipulate image databy performing image-filter operations, such as blur and sharpen.
  • Java 2 Platform only
  • Provides the ability to drag and drop between a Java application and a native application.
  • Go to java.sun.com. This is a very useful site and it is where I got my information for this presentation
  • Theres a tutorial which takes you step by step on how to use Swing components.
  • What is JFC?
  • What is Swing?
  • Name the Swing components?
  • Name 3 general purpose containers of Swing?
  • What does the Pluggable look and feel support does?

PowerShow.com is a leading presentation sharing website. It has millions of presentations already uploaded and available with 1,000s more being uploaded by its users every day. Whatever your area of interest, here you’ll be able to find and view presentations you’ll love and possibly download. And, best of all, it is completely free and easy to use.

You might even have a presentation you’d like to share with others. If so, just upload it to PowerShow.com. We’ll convert it to an HTML5 slideshow that includes all the media types you’ve already added: audio, video, music, pictures, animations and transition effects. Then you can share it with your target audience as well as PowerShow.com’s millions of monthly visitors. And, again, it’s all free.

About the Developers

PowerShow.com is brought to you by  CrystalGraphics , the award-winning developer and market-leading publisher of rich-media enhancement products for presentations. Our product offerings include millions of PowerPoint templates, diagrams, animated 3D characters and more.

World's Best PowerPoint Templates PowerPoint PPT Presentation

IMAGES

  1. Java Swing

    presentation on java swing

  2. PPT

    presentation on java swing

  3. PPT

    presentation on java swing

  4. PPT

    presentation on java swing

  5. PPT

    presentation on java swing

  6. PPT

    presentation on java swing

VIDEO

  1. Java swing in class

  2. Java Swing Basics

  3. Java Swing Application Explain 1

  4. Java Swing Application 2 (Netbeans Introduction)

  5. Java Swing #08 (JRadioButton)

  6. Java Swing Application Development Day 2

COMMENTS

  1. PPT Java Swing

    Aesthetic and minimalist design Swing is designed in a way that it provides a set of "lightweight" (all-Java language) components that, to the maximum degree possible, work the same on all platforms It includes almost only and all components we could find around any software with user interface Yet, it gives developers varieties to customize ...

  2. Java Swing

    Aug 30, 2012 • Download as PPTX, PDF •. This document provides an overview of Java Swing, which is a GUI widget toolkit for Java. It discusses the key features of Swing such as look and feel, data transfer, internationalization, and accessibility. It also describes the main Swing components including top-level containers, general purpose ...

  3. Java Swing

    8 likes • 1,496 views. Arkadeep Dey. Follow. Swing is a GUI widget toolkit for Java. It is part of Oracle's Java Foundation Classes (JFC) - an API for providing a graphical user interface (GUI) for Java programs. Read more. 1 of 31. Java Swing - Download as a PDF or view online for free.

  4. Java Swing Tutorial

    Java Swing tutorial is a part of Java Foundation Classes (JFC) that is used to create window-based applications. It is built on the top of AWT (Abstract Windowing Toolkit) API and entirely written in java. Unlike AWT, Java Swing provides platform-independent and lightweight components. The javax.swing package provides classes for java swing API ...

  5. PPT

    Introduction to Java Swing "We are the sultans of swing" - Mark Knopfler. What it is • Swing is the primary JavaGUIwidget toolkit. It is part of Oracle's Java Foundation Classes (JFC) — an API for providing a graphical user interface (GUI) for Java programs. • More sophisticated set of GUI components than the earlier Abstract Window ...

  6. Java swing

    Java Swing is a GUI toolkit that is used to create window-based applications. It is built on top of AWT and provides more powerful and lightweight components like tables, lists, scroll panes etc. Swing components are platform-independent and follow the MVC architecture. Common Swing components include JButton, JTextField, JTextArea and common ...

  7. Introduction to Java Swing

    Introduction to Java Swing. Swing is a Java Foundation Classes [JFC] library and an extension of the Abstract Window Toolkit [AWT]. Java Swing offers much-improved functionality over AWT, new components, expanded components features, and excellent event handling with drag-and-drop support. Swing has about four times the number of User Interface ...

  8. PPT

    Presentation Transcript. What is Java Swing? • Part of the Java Foundation Classes (JFC) • Provides a rich set of GUI components • Used to create a Java program with a graphical user interface (GUI) • table controls, list controls, tree controls, buttons, and labels, and so on…. What features are available?

  9. PPT

    Introduction • Swing is a set of classes that provides more powerful and flexible components than are possible with the AWT. • Swing supplies several exciting additions, including tabbed panes, scroll panes, trees, and tables. • Swing components are written entirely in Java and, therefore, are platform-independent.

  10. Java Swing.

    Download presentation. Presentation on theme: "Java Swing."—. Presentation transcript: 1 Java Swing. 2 AWT to Swing AWT: Abstract Windowing Toolkit Swing: new with Java2. import java.awt.* Swing: new with Java2 import javax.swing.*. Extends AWT Tons o' new improved components Standard dialog boxes, tooltips, ….

  11. Java SWING Tutorial: Container, Components and Event Handling

    The Swing framework in Java is built on top of the AWT framework and can be used to create GUI applications just like AWT. But unlike AWT, the Swing components are light-weight and are platform-independent. The Swing framework is written entirely in Java. The Swing framework in Java is provided through the 'javax.swing' package. The classes ...

  12. Java Swing

    Java Swing.ppt - Free download as Powerpoint Presentation (.ppt), PDF File (.pdf), Text File (.txt) or view presentation slides online. Swing is Java's graphical user interface toolkit that was created to replace the original AWT GUI subsystem, providing more powerful and flexible lightweight components whose look and feel can be customized, as well as support for pluggable look and feels to ...

  13. Java Swing

    Java Swing SlideshowCreate slideshow with animation using java swing with timing framework library and miglayout library.🙏🙏🙏 Support me by subscribe 🙏🙏...

  14. SWING USING JAVA WITH VARIOUS COMPONENTS

    Download now. SWING USING JAVA WITH VARIOUS COMPONENTS. 1. 2. Swing in java is part of Java foundation class which is lightweight and platform independent. It is used for creating window based applications. It includes components like button, scroll bar, text field etc. The javax.swing package provides classes for java swing API such as JButton ...

  15. PPT

    Java Swing - Lecture 2 Components and Containment Boriana Koleva ([email protected]) Components and Containers Components The building blocks Variety of uses and ... - A free PowerPoint PPT presentation (displayed as an HTML5 slide show) on PowerShow.com - id: 651c63-OTE1N

  16. 4-Class-Java Swings

    4-Class-Java Swings.ppt - Free download as Powerpoint Presentation (.ppt), PDF File (.pdf), Text File (.txt) or view presentation slides online. JFrame, JButton, and JOptionPane are major swing components. JFrame is used to set the title and border of a window. JButton simulates a push button. JOptionPane displays dialog boxes to take input or show output.

  17. Java swings

    Swing is the primary Java GUI widget toolkit. It is highly customizable and extensible, allowing users to override default implementations and extend the framework. Swing components are lightweight because they do not require allocating native operating system resources. Common Swing components include buttons, lists, menus, frames, and panels. 1.

  18. PPT

    220 likes | 467 Views. Java Swing. Chris North cs3724: HCI. AWT to Swing. AWT: Abstract Windowing Toolkit import java.awt.* Swing: new with Java2 import javax.swing.*. Extends AWT Tons o' new improved components Standard dialog boxes, tooltips, …. Look-and-feel, skins Event listeners API: Download Presentation.

  19. Java Swing

    Java Swing Chris North cs3724: HCI AWT to Swing AWT: Abstract Windowing Toolkit import java.awt.* Swing: new with Java2 import javax.swing.* Extends AWT Tons o new ... - A free PowerPoint PPT presentation (displayed as an HTML5 slide show) on PowerShow.com - id: 4204ba-YWViN

  20. Java Swing and Presentation Model

    Oct 9, 2013 at 10:06. @kleopatra Fowler suggests in his article that either Presentation Model or View should deal with synchronization and there are two ways to do that. One is to have view reference in your Presentation Model which is better from TDD perspective. The Second one is to have View dealing with synchronization and that is ...

  21. PPT

    Java Swing, Events. Readings: Just Java 2 : Chap 19 & 21, or Eckel's Thinking in Java : Chap 14 Slide credits to CMPUT 301, Department of Computing Science University of Alberta. Java Foundation Classes. JFC: Abstract Window Toolkit (AWT) original user interface toolkit don't go there!

  22. JAVA SWING

    About This Presentation. Title: JAVA SWING. Description: JFC stands for Java Foundation Classes, and it includes a group of features to ... For example, if you get carpal tunnel syndrome, you can use assistive ... - PowerPoint PPT presentation. Number of Views: 1550. Avg rating:3.0/5.0.

  23. Awt and swing in java

    Awt and swing in java. This document provides an overview of AWT and Swing. It discusses how AWT provides cross-platform functionality through abstract classes and platform-specific peer classes. It also summarizes the evolution of Swing from early versions of AWT that had limitations. Key points covered include: - AWT uses abstract classes and ...