aspose file tools*
The moose likes Beginning Java and the fly likes JTabbedPane pblm. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JTabbedPane pblm." Watch "JTabbedPane pblm." New topic
Author

JTabbedPane pblm.

Arun Martin
Ranch Hand

Joined: Dec 01, 2000
Posts: 64
Hi,
I am designing a swing application. I am to use JTabbedPanes. In one JFrame screen, I want two JTabbed Panes
(1).Add New User
(2).Change New User.
(1) contains a Label "ADD".
(2) contains a Label "MODIFY"
What I require:
1. When I click "Add New User" tab, "ADD". should be displayed hiding "MODIFY"
2. When I click " Change New User" tab, "MODIFY". should be displayed hiding "ADD".
Problems faced:
----------------
1. When first time I run the pgm,I click the ADD User Tab, nothing is displayed.
Then I click the MODIFY Tab, "MODIFY" is displayed and after that when I click ADD Tab,the same label "modify" is being displayed and then "modify" is always displaced irrespective of the tabbed panes clicked.
What could be the cause of this?.
2. I changed the setLayout(null) so that I could position components according to my desired locations. The pgm is running but only the blank JFrame is displayed. Will JTabbedPannes not work in setLayout(null)?.
3. There are only 2 JTabbedpanes. They occupy only a portion of the top left hand side of the screen. Is there any method through which I can place the 2 panes equidistant from each other?
The Program:
------------
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();
JLabel lmodifyUser = new JLabel();
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.
with warm regards,
Arun.
Lucas Richardson
Ranch Hand

Joined: Jul 08, 2001
Posts: 32
Try getting rid of the setVisible code. The tabbed pane will take care of displaying the correct components.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTabbedPane pblm.
 
Similar Threads
In JTabbedPane, updation of database values not working
JTabbedPane pblm.
JTextField : setText() is not working. getText() is working
JTabbedPane pblm.
In JTabbedPane, updation of database values not working