JLabel in Java Swing

The JLabel class is a Swing component for placing text in a container. It is used to display a single line of read-only text. The text can be changed by an application and can’t be edited by the user directly. … Read More

JButton in Java Swing

The JButton class is used to create a labeled button that has a platform-independent implementation. The application results in some action when the button is pushed. It inherits AbstractButton class. Constructors Constructor Description JButton() Creates a button with no set … Read More

Difference between AWT and Swing

AWT and swing are the Java API and both can be used to create a Graphical User Interface (GUI) based application in Java. The Java Foundation Classes (JFC) are a set of GUI components that simplify the development of Desktop … Read More

Why Do We Need a Top Level Container Like JFrame?

Top-level containers like JFrame are needed in Java GUI programming. These containers provide a way to display a Graphical User Interface (GUI) on the computer screen. A top-level container is a container that can be displayed on its own. Without … Read More

Create 2D shape in Java

To create a 2D shape in Java Swing, we can use the Graphics2D class, which provides a set of methods to draw and manipulate shapes. Following is an example of how to create a simple rectangle shape: In this example, … Read More

Display Image in Java Swing Application

To display an image in a Java Swing application, we can use the JLabel component to hold the image and add it to a container, such as a JFrame or JPanel. Following are the steps we can follow: JFrame frame … Read More

Use Font in Java Swing Application

In Java Swing application, we can use different fonts for displaying text in graphical user interface components like labels, buttons, text fields, and so on. Following is an example code snippet that demonstrates how to set a custom font for … Read More

Using Color in Java Swing

To use color in Java Swing, we can follow these steps: Color myColor = new Color(red, green, blue); // replace red, green and blue with the RGB values (0-255) of the desired color Alternatively, you can use one of the … Read More

JDesktopPane vs JInternalFrame in Java Swing

Both JInternalFrame and JDesktopPane are Java Swing components that can be used to create desktop applications with multiple windows. JInternalFrame is a container that represents a subwindow within a main window. It is typically used to display information or allow … Read More

JInternal Frame in Java Swing

JInternalFrame is a class in Java Swing that provides a lightweight way to create internal frames within a main frame or a desktop pane. Following are the steps to use JInternalFrame in Java Swing: JInternalFrame internalFrame = new JInternalFrame(“Internal Frame … Read More