Hello. I have an application running on JTabbedPane which consists of two
JPanels. When the application is first launched, it shows components on
both tabs until I click on one of the tabs, which then displays only the
components on the tab.

Each tab consists of it's own GridBagLayout and components are added to it.

The code is quite long but just to give you the idea,

public void init()
{
resize(660, 600);
setBackground(Color.lightGray);
setLayout(new GridLayout());

JTabbedPane mTabbedPane = new JTabbedPane();
mTabbedPane.addTab("Recording Mode",recordPanel());
mTabbedPane.addTab("Playing Mode",playPanel());
mTabbedPane.setSelectedIndex(0);
add(mTabbedPane);
addMouseListener(this);
}

public JPanel recordPanel()
{
JPanel recPanel = new JPanel(false);
GridBagLayout recGridBag = new GridBagLayout();
GridBagConstraints recConstraints = new GridBagConstraints();
recPanel.setLayout(recGridBag);
Insets mInsets = new Insets(10,30,10,30);
*---------components added to the recGridBag---omitted------*

public JPanel playPanel()
{
JPanel playPanel = new JPanel(false);
GridBagLayout playGridBag = new GridBagLayout();
GridBagConstraints playConstraints = new GridBagConstraints();
playPanel.setLayout(playGridBag);

*---------components added to the playGridBag---omitted------*

Thank you.