Home » Desktop Java » swing

swing

JTextarea Swing example

1. Introduction In this post, I’ll be giving an example of using JTextArea Swing component. This component is usually used to create an input text that can get large strings of data. Large strings of data can be, xml, html, source code or even an entire metadata string. 2. The example For this example, we’ll be making a basic JTextArea ...

Read More »

Java Swing Radio Button Example

Introduction The radio button is a one of the core components that has been introduced ever since the early foundations of graphical user interface development. The very aspects of it is that it allows the user to select one value from a group of values. In this post, I’ll be walking you through how it’s easy to create a radio ...

Read More »

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. This component also allows the user to select one or more elements visually. This article shows how to work with JList features using a simple example where we build a GUI with a JList to ...

Read More »

JFileChooser Swing Example

The JFileChooser Component is used to create a cross platform directory explorer that can be used for a Java Desktop Application. For this blog post, I’ll showcase the how to use the component and call it from a Java class.       1. Import the necessary objects   We need to import the following objects on your java class. ...

Read More »

JMenu Swing Example

1. Introduction A lot of IDEs supports dragging and dropping components to create a Java Desktop application, it’s always good to know by hand what is going on in the code to piece together the components. For this post, I’m going to show you step by step on how to create your own JMenu swing component.   2. Step by ...

Read More »

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. Those renderers are capable of rendering Boolean choices, dates, image icons, numbers, and objects (as strings). If you do not explicitly attach a custom render to a column, a ...

Read More »

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. This article is built into two steps. The first step has the following: Creation of Validator UI createValidatorUI method is invoked ...

Read More »

Java JDialog example

This is a tutorial of how to create dialog windows, using the JDialog class of the javax.swing package. The Swing API provides libraries to create a Graphical User Interface in platform independent way. It follows the MVC architecture. It consists of UI elements, which are the visual elements that a user interacts with, layouts, which define the use of the ...

Read More »

Java JFrame Example

In this article, we will see a JFrame Example and we will discuss some of JFrame main methods. We will also see how JFrame and other main classes like JPanel, JLabel, and JButton fit into the Swing hierarchy. We will then create a simple GUI using the javax.swing package. 1. Introduction JFC (Java foundation classes) encompasses a group of features ...

Read More »

Set tool tip for tab in JTabbedPane

With this example we shall see how to set the tool tip for a tab in JTabbedPane. In order to do that, one should follow these steps: Create a new JFrame. Call frame.getContentPane().setLayout(new GridLayout(1, 1) to set up grid layout for the frame. Use JTabbedPane(JTabbedPane.TOP) to get a JTabbedPane. Use tabbedPane.addTab to add a tool tip. Let’s see the code: ...

Read More »