Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTabbedPane  RSS feed

 
Anagha Medicharla
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
In my project I have created many forms like candiateInfo,Resume etc.(which extends JFrame)
Now I want to use JTabbedPane.Menas if I click on one tab it should take user to resp. form.Code I have written like this(it's in contstructor of that class):
[code]{ contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
JTabbedPane tabbedPane = new JTabbedPane();
String tabs[] = {"CandidateInfo", "Resume"};
tabbedPane.addTab(tabs[0], new Candidate());
tabbedPane.addTab(tabs[1], new Resume());
tabbedPane.setSelectedIndex(0);
add(tabbedPane, BorderLayout.CENTER);

this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
}
****It's giving runtime error- IllegalArgumentException:a window added to a conatainer.Can anybody explain me why it's giving this error.

Thanks in advance
Anagha

------------------
 
Chris Shepherd
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah your problem is that your forms extend JFrame (which is an individual window Object and does not extend Component) You need to extend JPanel in these forms to be able to add them as components in a tabbed pane. If they also need to be standalone windows soemtimes, just make a constructor of the form that creates a JFrame and adds itself to the JFrame.
Hope this helps.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!