by Dinesh Thakur Category: Swing

In order to add a component to a container, first create an instance of the desired component and then call the add () method of the Container class to add it to a window. The add() method has many forms and one of these is,

Component add (Component c)

This method adds an instance of Component (i.e. c) to the container. The component added is automatically visible whenever its parent window is displayed.

import javax.swing.*;

class AddComponentJFrame
      public static void main(String args[])
           JFrame frame = new JFrame("Add Components to JFrame Java Example");
           JButton button = new JButton("OK");

Add Components to JFrame Java Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles