943,070 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 6890
  • Java RSS
Jan 9th, 2008
0

adding a JFrame component to JTabbedPane

Expand Post »
Hello folks,

I am trying to add a JFrame object into JTabbedPane, but I am getting a java.lang.IllegalArgumentException. Here's my code snipt.

Java Syntax (Toggle Plain Text)
  1. // other codes...
  2. JTabbedPane tabs = new JTabbedPane();
  3. tabs.addTab("Flight Information",flightInfoPane); <-------------- line 28
  4. // other codes...
  5. private FlightInfoPane flightInfoPane = new FlightInfoPane();
Here I have flightInfoPane class's declaration...

Java Syntax (Toggle Plain Text)
  1. class FlightInfoPane extends JFrame {
  2. public FlightInfoPane () {
  3. }
  4. // rest of the class ....
  5. }

This is the error that I am getting. I am not sure if this operation is allowed.
Java Syntax (Toggle Plain Text)
  1. F:\DCTM_WORK>java FlightReservationDesktop.Reservation
  2. Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container
  3. at java.awt.Container.addImpl(Unknown Source)
  4. at javax.swing.JTabbedPane.insertTab(Unknown Source)
  5. at javax.swing.JTabbedPane.addTab(Unknown Source)
  6. at FlightReservationDesktop.Reservation.<init>(Reservation.java:28)
  7. at FlightReservationDesktop.Reservation.main(Reservation.java:35)

please advise...


Thanks.
Similar Threads
Reputation Points: 7
Solved Threads: 6
Junior Poster
new_2_java is offline Offline
127 posts
since Apr 2007
Jan 9th, 2008
2

Re: adding a JFrame component to JTabbedPane

A JFrame is a top-level component. It can not be "added" to another. Use a JPanel.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jan 9th, 2008
0

Re: adding a JFrame component to JTabbedPane

I agree with Masijade, and I think you could probably just change the JFrame inheritance to JPanel, well depending on your actual coding hehe Anyway, what I wanted to recommend is NetBeans. It’s a very innovate IDE when one is dealing with GUI applications You’d just create a new Java project and create a new GUI form; then you can drag and drop components just like in Visual Basic, but since it's Java it's better You certainly don’t have to code within NetBeans; just copy the automatically generated GUI code to the IDE that you’re using.
Last edited by PoovenM; Jan 9th, 2008 at 3:28 am.
Reputation Points: 56
Solved Threads: 11
Junior Poster
PoovenM is offline Offline
146 posts
since Aug 2006
29 Days Ago
0
Re: adding a JFrame component to JTabbedPane
you can not add jrame into jtabbedpane...but you can add jtabbedpane into jframe.
create jpanels and add them into addTab().
Reputation Points: 10
Solved Threads: 0
Newbie Poster
test.tracker is offline Offline
1 posts
since Dec 2011
Message:
Previous Thread in Java Forum Timeline: programming a java application to learn
Next Thread in Java Forum Timeline: JScrollPane not showing scroller





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC