help with inserting an internal frame into a tabbed pane

J

Justin

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

Michael Rauscher

Justin said:
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.

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

Bye
Michael
 
J

Justin

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

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

Michael Rauscher

Justin said:
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.
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
 
J

Justin

Id like a tab where the user can view and move around multiple windows
at the same time.
 
M

Michael Rauscher

Justin said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top