- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the importance of the Container class in Java?
Container
- A Container class can be described as a special component that can hold the gathering of the components.
- There are two types of Swing Containers, they are top-level containers and low-level containers.
- Top-Level containers are heavyweight containers such as JFrame, JApplet, JWindow, and JDialog.
- Low-Level containers are lightweight containers such as JPanel.
- The most commonly used containers are JFrame, JPanel and JWindow.
- The important methods of the Container class are add(), invalidate() and validate().
Example
import java.awt.*; import javax.swing.*; public class ContainerTest extends JFrame { // top-level container JPanel panel; // low-level container JTextField field; JButton btn; public ContainerTest() { setTitle("Container Test"); panel = new JPanel(); field = new JTextField(20); panel.add(field); btn = new JButton("Submit"); panel.add(btn); add(panel, BorderLayout.CENTER); setSize(350, 275); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); } public static void main(String args[]) { new ContainerTest(); } }
Output
- Related Articles
- What is the importance of SwingUtilities class in Java?
- What is the importance of Runtime class in Java?
- What is the importance of JViewport class in Java?
- What is the importance of JSeparator class in Java?
- What is the importance of the GridBagConstraints class in Java?
- What is the importance of the CardLayout class in Java?
- What is the importance of Boolean class in Java?\n
- What is the importance of a Cursor class in Java?
- What is the difference between Component class and Container class in Java?
- What is the importance of a SwingWorker class in Java?\n
- What is the importance of the Throwable class and its methods in Java?
- What is the importance of "Java.lang.Class" in Java?
- What is the importance of OverlayLayout in Java?
- Importance of StringReader class in Java?\n
- Importance of a Dictionary class in Java?

Advertisements