Results 1 to 4 of 4
  1. #1
    hendrix79 is offline Member
    Join Date
    Dec 2008
    Posts
    28
    Rep Power
    0

    Default Dispose a JDesktopPane for logout.

    Hello friends!

    I have to dispose() a JDesktopPane so i can can instantiate "again" my application by calling the main method and by zeroing the user-id, which will be 'got' again when the user will log-in. I need this solution for a logout.
    So... how can i dispose a JDesktopPane? Is there any method to dispose a JDesktopPane and call a new method? I've done this:

    Java Code:
    logOut = new JButton();
    			panMenu.add(logOut);
    			logOut.setText("Uscita");
    			logOut.setBounds(10,500, 170, 20);
    			logOut.addActionListener(new ActionListener() {
    				public void actionPerformed(ActionEvent evt) {
    					java.awt.Window[] a = java.awt.Window.getWindows();
    					int c = a.length;
    					for (int i=0; i<c; i++) {
    						a[i].dispose();
    					}
    				}
    			});
    and it closes me every window opened. This is good for exiting the application, but... what if i don't want to exit but just dipose the actual pane and calling another one?

    Thanks!!! :)

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    Just keep track of the pane in question, using an instance variable, and dispose() it.

    By the way, you might want to rethink your overall approach. There is no reason to kill the application just because the user logged out. You might want to instantiate some of the model classes and clean up some of the views, but starting again in the main() is a bit extreme.

  3. #3
    hendrix79 is offline Member
    Join Date
    Dec 2008
    Posts
    28
    Rep Power
    0

    Default

    Well, i only used one panel, so there's no need to keep track of it.
    So... the solution is to clear everything (user id too), right?

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    JDesktopPane is a container, like JFrame. However, the purpose of JDesktopPane is to allow you to create multiple JInternalPane's that can overlap each other, in what is called a MIDI (Multiple Independent Document Interface) application. The GIMP graphics application is a good example. It has several independent windows float around the display.

    What I'm trying to get at is this: Don't dispose the container; just remove and dispose the panes you add to it. This is a good reason not to add individual components to the container's content pane, it makes switching from one view to another more difficult. For that matter, if you have two views and you want to switch back and forth, create two JPanel's, each containing one view. Remove one, add the other, but dispose either. That will make you application use far less resources.

    In addition, why are you using JDesktopPane? Unless you want to create a MIDI application, just use JFrame. That creates a typical application appearance.

    Here's my suggestion. Take the various groups of components you've created and place them in separate JPanel's. Change the JDesktopPane to a JFrame, unless you plan to use JInternalPane's. Handle your applications logic flow by adding and removing the various JPanel's. Only dispose a JPanel if you don't intend to use it again.

    In each JPanel, add a method to reset all the components to their default values, so each panel can be reused.

Similar Threads

  1. JDesktoppane?
    By skatefreak in forum New To Java
    Replies: 2
    Last Post: 01-31-2009, 06:32 PM
  2. How to clear JDesktopPane
    By hendrix79 in forum New To Java
    Replies: 12
    Last Post: 12-11-2008, 12:25 AM
  3. How to dispose tooltip.
    By Preethi in forum New To Java
    Replies: 1
    Last Post: 07-22-2008, 08:06 AM
  4. JDesktopPane demo
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-26-2008, 08:43 PM
  5. How to add SystemTray to JDesktopPane
    By elisabethkron@yahoo.co.uk in forum Advanced Java
    Replies: 0
    Last Post: 04-07-2008, 09:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •