adding a JFrame component to JTabbedPane

Reply

Join Date: Apr 2007
Posts: 126
Reputation: new_2_java is an unknown quantity at this point 
Solved Threads: 6
new_2_java new_2_java is offline Offline
Junior Poster

adding a JFrame component to JTabbedPane

 
0
  #1
Jan 9th, 2008
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.

  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...

  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.
  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,326
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 248
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: adding a JFrame component to JTabbedPane

 
1
  #2
Jan 9th, 2008
A JFrame is a top-level component. It can not be "added" to another. Use a JPanel.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 137
Reputation: PoovenM is on a distinguished road 
Solved Threads: 11
PoovenM PoovenM is offline Offline
Junior Poster

Re: adding a JFrame component to JTabbedPane

 
0
  #3
Jan 9th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC