• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTabbedPane

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

------------------
 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic