Java Swing Tutorials

Java Swing Tutorials

In this detailed Resource page, we feature an abundance of Java Swing Tutorials!

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.

Swing was developed to provide a more sophisticated set of GUI components than the earlier Abstract Window Toolkit (AWT). Swing provides a look and feel that emulates the look and feel of several platforms, and also supports a pluggable look and feel that allows applications to have a look and feel unrelated to the underlying platform. It has more powerful and flexible components than AWT. In addition to familiar components such as buttons, check boxes and labels, Swing provides several advanced components such as tabbed panel, scroll panes, trees, tables, and lists.

Unlike AWT components, Swing components are not implemented by platform-specific code. Instead, they are written entirely in Java and therefore are platform-independent. The term “lightweight” is used to describe such an element.

The Internet Foundation Classes (IFC) were a graphics library for Java originally developed by Netscape Communications Corporation and first released on December 16, 1996. On April 2, 1997, Sun Microsystems and Netscape Communications Corporation announced their intention to incorporate IFC with other technologies to form the Java Foundation Classes. The “Java Foundation Classes” were later renamed “Swing.”

Swing introduced a mechanism that allowed the look and feel of every component in an application to be altered without making substantial changes to the application code. The introduction of support for a pluggable look and feel allows Swing components to emulate the appearance of native components while still retaining the benefits of platform independence. Originally distributed as a separately downloadable library, Swing has been included as part of the Java Standard Edition since release 1.2. The Swing classes and components are contained in the javax.swing package hierarchy.

Note
If you wish to build up your Swing knowledge first, check out our Java Swing Tutorial for Beginners.

Java Swing Tutorials – Getting Started

Simple examples based on Java Swing

  • Java Swing Key Binding Example
    In this example key binding is exhibited by means of using Keymap. For more generalized purpose we can use InputMap and ActionMap combination or even combination of Keymap and InputMap.
  • Java Swing Drag and Drop Example
    This example is used to describe default as well as customized drag and drop. We have considered 4 different types of components to describe.
  • Java Swing Date Picker Example
    In this section, you will learn how to display date picker using java swing. The date picker lets the user select the Date through an easy interface that pops up with a Calendar.
  • Java Swing Calculator Example
    This tutorial is about how to make a calculator in Java. Below I have shared the simple calculator program in java using swing.
  • Java Swing ActionListener Example
    Action listeners are probably the easiest — and most common — event handlers to implement. You implement an action listener to define what should be done when an user performs certain operation.
  • How to Close an Application Properly
    Here is a code example of closing Java program by calling System.exit() method.
  • Java Swingx Game Example
    In this example we will demonstrate how to develop a game using JAVA Swing.
  • Java Swingx Example
    In this example we will demonstrate how to build an application using Java Swing.
  • Java AWT Graphics Example
    The Java 2D API is powerful and complex. However, the vast majority of uses for the Java 2D API utilize a small subset of its capabilities encapsulated in the java.awt.Graphics class.
  • How to Create a Gui in Java With Swing
    In this example we will learn how to create a GUI using eclipse in JAVA.
  • Java Swing Timer Example
    In this example we are going to demonstrate Java Swing Timer, A swing timer fires one or more ActionEvent at specified intervals.
  • JAVA Swing Application Example
    This is an example of creation of a JAVA Swing Hello world application.
  • How to Create GUI in JAVA
    Java Graphics APIs – AWT and Swing – provide a huge set of reusable GUI components, such as button, text field, label, choice, panel and frame for building GUI applications.
  • JAVA Swing List Example
    JList is a swing component through which we can display the list of objects. This swing component allows user to select one or more elements. Lists can have many items, so they are often put in scroll panes.
  • JAVA Swing Button Example
    In this article we will learn different types of Button and how to create them. A button is a component that a user clicks to trigger a specific action.
  • JAVA Swing Table Example
    In this example we will learn how to create a Table using JTable component in Swing. Data can be viewed or edited using the JTable component.
  • JAVA Swing Form Example
    With this example we are going to demonstrate creation of form using JAVA Swing. JAVA provides a huge set of libraries to develop a Graphical User Interface.
  • Java Swing Slider example
    In this article, we’ll discuss Java swing slider. In Java Swing, slider is normally constructed by a JSlider component.
  • Java Swing Checkbox Example
    In this article, Java swing checkbox will be discussed. checkbox is to present whether an item has been selected or unselected.
  • OpenMap Tutorial – Part 1
    In this first tutorial we shall build a basic JFrame application that contains a map.
  • OpenMap Tutorial – Part 2
    In this tutorial we learned how to use: MapBean, MapHandler, LayerHandler, PropertyHandler, ShapeLayer, GraticuleLayer, OpenMapFrame.

Java Swing Tutorials – Layout Manager

Simple examples based on Swing Layout Manager

  • Java Swing Layout Example
    In Java swing, Layout manager is used to position all its components, with setting properties, such as the size, the shape and the arrangement.
  • Java Swing BoxLayout example
    In Java Swing, layout manager is in charge of laying out different components in specific positions. In this article, we’ll focus on BoxLayout and go through the basic operation on it.
  • Java Swing GridLayout Example
    This example shows a scenario to use GridLayout while developing UI. There can numerous such scenarios for use of this. For any further reading, supplied links can be referred.
  • Java Swing Gridbaglayout Example
    GridBagLayout is one of the most flexible — and complex — layout managers the Java platform provides.
  • Java Swing FlowLayout Example
    The FlowLayout class provides a very simple layout manager that is used, by default, by the JPanel objects.

Java Swing Tutorials – JComponents

Simple examples based on Swing JComponents

  • JAVA Swing Component Tutorial
    This lesson gives you the background information you need to use the Swing components, and then describes every Swing component.
  • Java Swing JWindow Example
    A JWindow is a container that can be displayed anywhere on the user’s desktop.
  • Java Swing JTextField Example
    In this example common operations of JTextField are addressed. For further reading links shared in this article can be referred.
  • Create JTextField with border
    In this tutorial we are going to see how to create a JTextField with border. This is a very simple way to make your component a little bit more interesting.
  • Create JTextField with tooltip
    With this example we are going to learn how to create a JTextField with a tootip. Tooltip texts are very useful because they explain to the users how to use a specific component.
  • Create read-only (non-editable) JTextField
    In this example we are going to see how to create read-only JTextFields in Java Desktop Applications.
  • Create new JTextField
    In this example we are going to see how to create a new JTextField component in a Java Desktop Application.
  • Set foreground color in JLabel
    With this example we shall show you how to set foreground color in a JLabel component in Java Desktop Applications. This will enrich and customize your GUI components.
  • Set background color in JLabel
    With this example we shall show you how to set background color in a JLabel component in Java Desktop Applications. This will enrich and customize your GUI components.
  • Create JLabel with border
    In this example we are going to see how to create a JLabel with border. This is one basic graphics enhancement for your application. In general, this is one of the main customizations you can perform to your JLabels.
  • Align Icon in JLabel
    With this tutorial we shall show you how to align Icons in JLabel. This is a very easy optimization you can perform to your JLabel.
  • Create JLabel with ImageIcon and text
    In this tutorial we are going to learn how to create a JLabel with ImageIcon and text in it. Using ImageIcons and text in Labels, usually makes them self explanatory to the end user.
  • Handle action events for JButton
    This is a tutorial on how to handle action events for JButtons components in a Java Desktop Application. JButtons are very frequently used, and it is a very standard practice to use buttons for basic input operations in GUI applications.
  • Create JButton example
    With this example we shall show you how to create a JButton component for your Java Desktop Application. JButtons are very frequently used, and it is a very standard practice to use buttons for basic input operations in GUI applications.
  • Set action command for JButton
    In this example we are going to see how to set action command for JButton component. This is a very important task when working in a Java GUI application, as most of the times you have to bundle a button with a specific action.
  • Create Checked/Unchecked JCheckBox
    With this example we shall show you how to create JCheckBoxes in a Java Desktop Application. Checkboxes are very commonly used when we provide the user with a list of choices and we want him to pick as many as he wishes.
  • Handle JCheckBox event
    In this example we are going to see how to handle JcheckBox events in a Java Desktop Application. Checkboxes are very commonly used when we provide the user with a list of choices and we want him to pick as many as he wishes.
  • Create new JCheckBox example
    With this example we shall show you how to create JCheckBoxes in a Java Desktop Application. Checkboxes are very commonly used when we provide the user with a list of choices and we want him to pick as many as he wishes.
  • Java Swing Radio Button Example
    In this post, I’ll be walking you through how it’s easy to create a radio button using the JRadioButton object from the swing framework.
  • Create grouped JRadioButtons with ButtonGroup
    In this tutorial we are going to see how to create grouped JRadioButtons using a ButtonGroup. When working with radio buttons in general, it’s usually pointless to create them independently from one another.
  • Get selected JRadioButton from ButtonGroup
    With this example we shall show you how to get the selected JRadioButton for a ButtonGroup in a Java Desktop Application.
  • Java JFrame Example
    In this example we will show how to use the class JFrame and how to create a simple gui by using the javax.swing package. JFrame class is one of the containers provided by the java.awt package.
  • Center JFrame/JWindow/JDialog on screen
    In this example we shall show you how to center JFrame, JWindow, JDialog components in a Java Desktop Application. You can use this when you want to center you windows in your application automatically.
  • Create JFrame window with mouse event handling
    This is an example that demonstrates how to create a JFrame windows that supports mouse event handling. This is very useful in most GUI applications because most of the time it is very efficient for the user to provide input using his mouse.
  • Create JFrame window with window close event
    This is an example on how to create a JFrame window with window close event. Pairing a window with a closing event is a very common practice in most GUI applications.
  • Create JFrame Window
    In this tutorial we are going to see how to create a JFrame window. The JFrame window is the single most important component in a Java Desktop Application.
  • Java JList Example
    In this example we are going to demonstrate how to use Java Swing JList, JList is a Swing component with which we can display a list of elements.
  • Get selected value from JList
    In this example we are going to learn how to get the selected value form a JList in a Java Desktop Application. This example is very useful because JList component provides a very easy way to get user input, especially when you want to give the user a number of specific options.
  • Create JList example
    In this example we are going to see how to create a JList component in a Java Desktop Application. The JList component provides a very easy way to get user input, especially when you want to give the user a number of specific options.
  • JFileChooser Swing Example
    The JFileChooser Component is used to create a cross platform directory explorer that can be used for a Java Desktop Application.
  • Create color chooser dialog
    With this tutorial we shall show you how to create a color chooser dialog in a Java Desktop Application.
  • Select file selection mode in file chooser
    With this tutorial we are going to see how to set the file selection mode in a file chooser of a Java Desktop Application. This is very useful when you want to search for a specific type of file in your file system.
  • Create file chooser dialog
    In this tutorial we are going to learn how to create a File Chooser Dialog in a Java Desktop Application. We all use file chooser dialogs on a daily basis.
  • Create JScrollPane example
    In this example we are going to see how to create a JScrollPane container in a Java Desktop Application.
  • Set scrollbar policy in JScrollPane container
    With this example we are going to see how to set scroll bar policy in a JScrollPane container. This is very useful when you want to further customize your scroll bars.
  • Handle scrollbar value changes in JScrollPane
    In this example we are going to see how to handle scroll bar value changes in a JScrollPane component.
  • JScrollPane Swing example
    In this post, I’ll be giving an example of using JScrollPane Swing component. This component is usually used to create a scroller on panels that has more content that it can display.
  • Get/Set divider size in JSplitPane
    This is an example on how to get or set the size of the divider in a JSplitPane component of a Java Desktop Application.
  • Get/Set divider location in JSplitPane
    In this example on how to get or set the location of the divider in a JSplitPane component of a Java Desktop Application.
  • Create JSplitPane example
    This is an example on how to create a new JSplitPane component for a Java Desktop Application.
  • Set tool tip for tab in JTabbedPane
    With this example we shall see how to set the tool tip for a tab in JTabbedPane.
  • Set tab color in JTabbedPane
    This is an example on how to set tab color in JTabbedPane.
  • Remove tab in JTabbedPane
    This is an example on how to remove a tab in a JTabbedPane component.
  • Get tab info in JTabbedPane
    In this example we are going to see how to get the tab info in a JTabbedPane component of a Java Desktop Application.
  • Get/Set selected tab in JTabbedPane
    With this tutorial we shall show you how to get or set the selected tab in a JTabbedPane component of a Java Desktop Application.
  • Enable scrolling tabs in JTabbedPane
    With this example we shall show you how to enable scrolling in a JTabbedPane component of a Java Desktop Application.
  • Add tab to JTabbedPane
    In this tutorial we are going to see how to add a tab to a JTabbedPane component of a Java Desktop Application.
  • Create JTabbedPane example
    With this example we shall show you how to create a JTabbedPane component in a Java Desktop Application.
  • Java JTable Example
    In this example we are going to demonstrate how to use Java Swing JTable, JTable is a Swing component with which we can display tables of data, optionally allowing the user to edit the data, JTable relies on a separate TableModel object to hold and represent the data it displays.
  • Drawing Swing JTable rows with different colors using TableCellRenderer interface Example
    In this example we are going to demonstrate how to use Java Swing TableCellRenderer interface to customize cell rendering. When a JTable object is created, several default renderers are also created.
  • Java JDialog example
    This is a tutorial of how to create dialog windows, using the JDialog class of the javax.swing package.
  • javax.swing.JLayer Example: A new Swing Feature in Java 7
    This is a example for JLayer class in javax.swing package. JLayer is a new swing feature in Java 7. In this example, JLayer is used to decorate and validate the Text Field & Date Field in the User interface.

[undereg]

Back to top button