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 / March 2006

Tip: Looking for answers? Try searching our database.

Problem adding/removing items to already visible components

Thread view: 
steve_marjoribanks@hotmail.com - 21 Mar 2006 16:12 GMT
I am having trouble figuring out the best solution to a problem. Seeing
as I am a beginner and this is my first application, I'm not yet quite
in the mindset of a programmer and so I'm struggling to visualize the
best solution so I was hoping you could help me :-)

The overall purpose of the application is to load data from an XML file
and then represent it graphically on one JPanel, and display a JTree
representation of the XML file in another JPanel. All the most
important sections of code appear to work, ie. it can open a file,
validate the XML, display the XML tree and draw the required pictorial
representation, but I am having some trouble working out how to remove
the minor 'display bugs'.

When run, the application opens up a 'main' window (JFrame) which
should have no initial visible content other than the menubar and
toolbar. This has a menu and toolbar etc. from which a File Chooser is
loaded when the user selects 'open'. On opening the XML file it is
validated and then a JTabbedPane with 2 tabs should be displayed
filling all the empty area in the main JFrame. One of these tabs
displays the pictorial representation of the data and the other the
JTree.

What I am having trouble working out is how to sructure my code so that
the JTabbedPane only appears on opening a file and is then disposed of
upon closing the file (ie the file is closed but the application remins
running so another file may be opened).

I considered changing the code to use a JDesktopPane instead of the
main JFrame and then opening up the file in an internal frame (the
ability to open multiple files like this within the same application
was a possible extension to my project) but I read in Sun's Swing
tutorial that this can be a non-trivial task.
I also though, would it be possible just to add the JTabbedPane on
loading the application and just use the setVisible method to make it
visible when a file is opened but then I thought that this would create
problems when closing the file as you can't just remove a component and
then add one again when the application is still running.

Any thoughts from people more experienced than me (thats's most of you,
lol) would be greatly appreciated!

Many thanks,
Steve
Thomas Weidenfeller - 21 Mar 2006 16:52 GMT
> What I am having trouble working out is how to sructure my code so that
> the JTabbedPane only appears on opening a file and is then disposed of
> upon closing the file (ie the file is closed but the application remins
> running so another file may be opened).

This is not what one typically does. It would be more typical to clean
out the contents in the different panes of the tabbed pane, and then
disable (grey-out) things by using setEnabled(false).

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

steve_marjoribanks@hotmail.com - 21 Mar 2006 17:16 GMT
>This is not what one typically does. It would be more typical to clean
>out the contents in the different panes of the tabbed pane, and then
>disable (grey-out) things by using setEnabled(false).

This is what I had planned to do orginally, but I had a look at the API
and couldn't find a method available for use on a JPanel which clears
out content other than remove(). I didn't think I could use 'remove'
because if I then want to open another file after the original one has
been closed, how can I get the new data to be displayed? I thought that
components could only be added to containers before the container is
displayed? What I am saying is that if I remove the scroll pane with
the JTree in it (as mentioned in the post above) upon closing the first
file, I didn't think it was then possible to add a new scroll pane and
JTree upon opening a new file if the aplpication is still running and
the GUI is visible?
Have I misunderstood the rules for adding components?

Steve
steve_marjoribanks@hotmail.com - 21 Mar 2006 18:42 GMT
After much searching I have come to the conclusion that I must use the
validate() method followed by a repaint() after adding/removing
components from the tabbed panes!


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.