You are here:   HomeJava ProgrammingSwingAdd Components to JFrame Java Example
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

Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes 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.

What's New and Popular

Popular Article