Upon analysis of your code I've noticed the following things:
The reason your labels are not showing up properly is because you are adding labels directly to the content pane (in your ChangeListener). Since you are not providing a layout model, they are being layed on top of each other, thus the last one added is the one that shows. This also explains why you see no label initially, but only after you click a tab (i.e. invoke the ChangeListener).
The easist solution is to provide the label text for the labels you created to add to the Tabbedpane:
public class Tabbedpane extends JFrame
{
Container container;
JTabbedPane tp;
JLabel laddUser = new JLabel("Add");
JLabel lmodifyUser = new JLabel("Modify");
...
And remove the mylabel stuff from the ChangeListener.
Java will automatically switch between components contained within the JTabbedPane component, you don't have to worry about that. You do need the stateChanged method, but you only need to worry about putting in actions to handle things outside of displaying the selected component.
Here is your code, refined:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
//public class ModifyProposal extends JInternalFrame
public class Tabbedpane extends JFrame
{
Container container;
JTabbedPane tp;
JLabel laddUser = new JLabel("Add");
JLabel lmodifyUser = new JLabel("Modify");
public Tabbedpane()
{
container=this.getContentPane();
//container.setLayout(null);
tp = new JTabbedPane();
tp.addTab("Add User",laddUser);
// When I click this tab, add User Details
//should be displayed
tp.addTab("Modify User",lmodifyUser);
// When I click this tab, Modify User Details
//should be displayed
tp.addChangeListener(new TPListener());
container.add(tp);
setSize(805,550);
setVisible(true);
}
class TPListener implements ChangeListener
{
JTabbedPane tempTP;
public void stateChanged(ChangeEvent ce)
{
int idx=0;
tempTP = (JTabbedPane) ce.getSource();
//JLabel myLabel1 = new JLabel("Add");
//JLabel myLabel2 = new JLabel("Modify");
//container.add(myLabel1);
//container.add(myLabel2);
idx = tempTP.getSelectedIndex();
if (idx==0)
{
//myLabel2.setVisible(false);
//myLabel1.setVisible(true);
}
else if (idx==1)
{
//myLabel1.setVisible(false);
//myLabel2.setVisible(true);
}
else
{
// do nothing
}
}
}
public static void main(String[] a)
{
Tabbedpane ob = new Tabbedpane();
}
} // end of pgm.
As far as for the placement of the tabs, the only things I am aware of is the JTabbedPane.setTabPlacement(int tabPlacement) method, which allows you to specify whether the tabs should be placed at the top, bottom, left, or right of the JTabbedPane. This can also be specified in the constructor.
Hope this helps.
Sean C. Mitchem