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 / GUI / February 2005

Tip: Looking for answers? Try searching our database.

Changing a Panel at run time.

Thread view: 
IchBin - 12 Feb 2005 02:41 GMT
Not sure how to do this.

Simple example would be say I have a JTabbedPane with a JPanel object on
it. How do I drop\replace this JPanel to load a newer modified one while
running.?

Based on what I am doing, on the JPanel, I have no problem dynamically
building the JPanels. Just not sure how to replace the JPanel that
resides on the JTabbedPane.

I really do not want to remove and then insert one of the indexed tabs
to just load a new JPanel on it.

Signature

Thanks in Advance...
IchBin
__________________________________________________________________________

'The meeting of two personalities is like the contact of two chemical
substances:  if there is any reaction, both are transformed.'
-  Carl Gustav Jung,  (1875-1961),  psychiatrist and psychologist

Rhino - 13 Feb 2005 16:19 GMT
> Not sure how to do this.
>
[quoted text clipped - 8 lines]
> I really do not want to remove and then insert one of the indexed tabs
> to just load a new JPanel on it.

Assuming your JPanel was instantiated as follows:

   JPanel myPanel = ....

All you need to do is:

   JPanel myNewPanel = ....
   myPanel = myNewPanel;

Rhino
Babu Kalakrishnan - 14 Feb 2005 06:16 GMT
>>Not sure how to do this.
>>
[quoted text clipped - 17 lines]
>     JPanel myNewPanel = ....
>     myPanel = myNewPanel;

That's a big fallacy.

What you suggested would make the reference "myPanel" to point to the
new JPanel, but will not change the JTabbedPane change the contents of
the tab which held myPanel earlier to display the new panel. (That's
what the OP wanted - if I understood the question correctly)

The basic issue here is understanding the difference between objects and
references. You need to understand that when you call
tabbedpane.addTab("SomeName",myPanel), what is added to the JTabbedPane
is *not* the reference "myPanel", but the JPanel object that myPanel is
pointing to at that moment. Once you have done this, changing the value
of myPanel to anything (even null) is not going to make any difference
to what is inside the JTabbedPane.

To the OP :

You could use the setComponentAt(int,Component) method to set the
Component at a specific index to a new Component. If you don't know the
index - but only the name of the tab, you could always get it using the
method indexOfTab.

BK
Bill Tschumy - 13 Feb 2005 19:10 GMT
> Not sure how to do this.
>
[quoted text clipped - 8 lines]
> I really do not want to remove and then insert one of the indexed tabs
> to just load a new JPanel on it.

myTabbedPane.remove(indexToReplace);
myTabbedPane.add(newPanel, indexToReplace);

Signature

Bill Tschumy
Otherwise -- Austin, TX
http://www.otherwise.com



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



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