Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

help with inserting an internal frame into a tabbed pane

Thread view: 
Justin - 25 Sep 2006 07:37 GMT
I took an intro course to OOP 4 years ago, and I have been recently
getting back into it again.  I  have a JTabbedPane and I would like to
put a JFrame within a JTabbedPane.  However, I am getting an error when
I add the JFrame to the JTabbedPane -

<font color="red">Exception in thread "main"
java.lang.IllegalArgumentException: adding a window to a container
</font><br><br>

I do this because I would like InternalFrames within the tabs.

I think the relevant code is here: <br><br>
<i>
   public JPanel createNewTab(){
       JPanel panel = new JPanel();
       externalFrame = new JFrame();
       //externalFrameMethod();
       panel.add(externalFrame);
       //panel.validate();
       return panel;
   }
</i><br><br>

The line that is causing the error is panel.add(externalFrame); line.

Any help would be greatly appreciated.
Michael Rauscher - 25 Sep 2006 07:43 GMT
Justin schrieb:
> I took an intro course to OOP 4 years ago, and I have been recently
> getting back into it again.  I  have a JTabbedPane and I would like to
[quoted text clipped - 6 lines]
>
> I do this because I would like InternalFrames within the tabs.

Why do you add a JFrame to the tab if you want to have a JInternalFrame?

Bye
Michael
Justin - 25 Sep 2006 14:36 GMT
> Justin schrieb:
> > I took an intro course to OOP 4 years ago, and I have been recently
[quoted text clipped - 12 lines]
> Bye
> Michael

I was under the assumption that an InternalFrame had to be inside a
Frame.  I have tried putting it directly into the JFrame, and it is
hardcore screwed up.  Its as if the JFrame is as small as possible to
contain a minimized internal frame even though I set the bounds of the
JFrame.

Sorry if this is a stupid question, I am hardcore newb and have been
stuck on this problem for 2 days.
Michael Rauscher - 25 Sep 2006 19:00 GMT
Justin schrieb:
>> Justin schrieb:
>>> I took an intro course to OOP 4 years ago, and I have been recently
[quoted text clipped - 20 lines]
> Sorry if this is a stupid question, I am hardcore newb and have been
> stuck on this problem for 2 days.

Then why do you want to add a JInternalFrame to a tab? Do you really
want a frame within a tab or do you only want a container within a tab
where you can add components to?

Bye
Michael
Justin - 25 Sep 2006 23:03 GMT
Id like a tab where the user can view and move around multiple windows
at the same time.

> Justin schrieb:
> >> Justin schrieb:
[quoted text clipped - 28 lines]
> Bye
> Michael
Michael Rauscher - 26 Sep 2006 12:08 GMT
Justin schrieb:
> Id like a tab where the user can view and move around multiple windows
> at the same time.

Ok, to use JInternalFrame you best add them to a JDesktopPane. The
following example shows a desktop within a tab page that contains two
internal frames: one that is resizable and closable and one that is
iconifiable.

import javax.swing.*;

public class Test  {

    public static final void main( String args[] ) {
        JDesktopPane desktop = new JDesktopPane();
        desktop.setPreferredSize( new java.awt.Dimension(600,400) );

        JInternalFrame iframe = new JInternalFrame("First Frame");
        iframe.setSize( 200, 100 );
        iframe.setVisible( true );
        iframe.setResizable( true );
        iframe.setClosable( true );
        desktop.add( iframe );

        iframe = new JInternalFrame("Second Frame");
        iframe.setSize( 200, 100 );
        iframe.setLocation( 200, 200 );
        iframe.setVisible( true );
        iframe.setIconifiable( true );
        desktop.add( iframe );

        JTabbedPane tabbedPane = new JTabbedPane();
        tabbedPane.addTab( "Desktop", desktop  );

        JFrame frame = new JFrame( "Test ");
        frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
        frame.setContentPane( tabbedPane );
        frame.pack();
        frame.setVisible(true);
    }
}

Bye
Michael


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.