Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 588
  • Last Modified:

Layout is not saved when i am using JInternalFrame as docking window

Hai,
I am implementing Docking Framework in my application. In that one feature is when I am closing the window, I want to save the current layout. Next time if I open that window it will open with Saved Layout.

I know it can be possible, but the thing is that it is working fine for Frames(extends from JFrame), but it is not working properly for internalFrames(extends from JInternalFrames). Means if I closed and immediately open the internal frame the saved layout is not reflected. In my application only Main Interface is extends from JFrame, remaining all screens are extends from JInternalFrame(those all are menu items).

If I want to implement this feature definitely it should be worked properly for InternalFrames. Is there any specific method for JInternalFrames or any other solution ?

Thank U.
0
krishnasaikarthik
Asked:
krishnasaikarthik
  • 2
  • 2
1 Solution
 
objectsCommented:
WOuld have thught it would be, if you can post a small example that demonstrates the problem that I can run here I'll see what I can find.
you're not recreating the frame everytime you open it are you?

Are the frame where it is working using the same layout? If not try using identical layouts in frame and internalframe and see if you get differences.
0
 
krishnasaikarthikAuthor Commented:

   
  Below code gives u some idea.i am using flexdock open source in my application.
site : https://flexdock.dev.java.net

   i am recreating the frame every time when i open it, here flexdock is provide some methods in that api, those are providing such facility.


Class 1:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import org.flexdock.demos.view.ViewDemo3;
import javax.swing.JDesktopPane;
import org.flexdock.docking.Dockable;
import org.flexdock.docking.DockingConstants;
import org.flexdock.docking.DockingManager;
import javax.swing.plaf.basic.BasicDesktopPaneUI;
import org.flexdock.view.View;
import org.flexdock.view.Viewport;

public class MenuGlueDemo extends JFrame implements ActionListener,DockingConstants{
    protected JMenuBar menuBar;
      JMenu m;
      JMenuItem menuitem;
      static JDesktopPane desktop;
      private Dockable dockableImpl;
    public MenuGlueDemo() {
        super("MenuGlueDemo");
        menuBar = new JMenuBar();
        setJMenuBar(menuBar);
        addNewMenu("Menu 1");
        menuitem.addActionListener(this);


            desktop = new JDesktopPane() {
                  public void updateUI() {
                        super.setUI(new BasicDesktopPaneUI());
                  }

                  public void setDesktopManager(DesktopManager d) {
                        // System.out.println("MainInterface . JDesktopPane . setDesktopManager");
                        super.setDesktopManager(d);
                  }
        };
            desktop.setDoubleBuffered(true);
            //desktop.setLayout(null);
            desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
            desktop.updateUI();
             this.getContentPane().add(desktop,BorderLayout.CENTER);
             View view=new View("","","");

        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }

      public void actionPerformed(ActionEvent ae) {
                    System.out.println("\n m.addActionListener() \n");
                   // dockableImpl=new ViewDemo();
                    //ViewDemo frame1 = new ViewDemo();
                    ViewDemo3 frame1 = new ViewDemo3();
                    frame1.setVisible(true);
              desktop.add(frame1);
         }


    public void addNewMenu(String title) {
            menuitem = new JMenuItem("Internal Frame");
            m = new JMenu(title);
            m.add(menuitem);
        menuBar.add(m);

    }


    public static void main(String args[]) {
        MenuGlueDemo f = new MenuGlueDemo();
        f.setSize(900, 750);
        f.setVisible(true);
   }
}



Class 2:

// Source File Name:   ViewDemo3.java
package org.flexdock.demos.view;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.*;


import org.flexdock.docking.Dockable;
import org.flexdock.docking.DockingConstants;
import org.flexdock.docking.DockingManager;
import org.flexdock.view.View;
import org.flexdock.view.Viewport;
import javax.swing.JInternalFrame;
import javax.swing.JFrame;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import org.flexdock.dockbar.Dockbar;
import org.flexdock.dockbar.DockbarManager;
import org.flexdock.docking.props.*;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalTheme;
import org.flexdock.docking.drag.effects.EffectsManager;
import org.flexdock.docking.drag.preview.GhostPreview;
import org.flexdock.docking.drag.preview.AlphaPreview;
import org.flexdock.docking.drag.preview.XORPreview;
import org.flexdock.docking.state.PersistenceException;
import org.flexdock.perspective.*;
import org.flexdock.perspective.actions.OpenPerspectiveAction;
import org.flexdock.perspective.persist.FilePersistenceHandler;
import org.flexdock.perspective.persist.xml.XMLPersister;


public class ViewDemo3 extends JInternalFrame
    implements DockingConstants
{
      static Viewport viewport=null;
      public static int noOfWindows;

      private static class ViewFactory extends org.flexdock.docking.DockableFactory.Stub
      {
            public Dockable getDockable(String dockableId) {
              System.out.println("\n getDockableComponent(String dockableId)123 \n");
              return null;
            }
         public Component getDockableComponent(String dockableId)
         {
                  System.out.println("\n getDockableComponent(String dockableId) ;;"+dockableId);
                  if("bird.view".equals(dockableId)){
                        System.out.println("\n bird.view.equals() \n");
                        return createView("bird.view", "Bird View");
                  }
                  if("message.log".equals(dockableId)){
                        System.out.println("\n message.log.equals() \n");
                        return createView("message.log", "Message Log");
                  }
                  if("problem".equals(dockableId)){
                        System.out.println("\n problem.equals() \n");
                        return createView("problem", "Problems");
                  }
                  if("console".equals(dockableId)){
                        System.out.println("\n console.equals() \n");
                        return createView("console", "Console");
                  }
                  else{
                        System.out.println("\n return null \n");
                        return null;
                  }

        }

            private View createView(String id, String text)
            {
                  System.out.println("\n createView() \n");
                  View view = new View(id, text);
                  view.addAction("close");
                  view.addAction("pin");
                  JPanel panel = new JPanel();
                  panel.setBorder(new LineBorder(Color.GRAY, 1));
                  JTextField textField = new JTextField(text);
                  textField.setPreferredSize(new Dimension(100, 20));
                  panel.add(textField);
                  view.setContentPane(panel);
                  return view;
            }
          private ViewFactory()
          {
          }
    }

    private static class DemoPerspectiveFactory implements PerspectiveFactory
      {
              public Perspective getPerspective(String persistentId)
              {
                  if("p1".equals(persistentId)){
                              System.out.println("\n p1.equals(persistentId) \n");
                      return createPerspective1();
                        }
                  else
                      return null;
              }

              private Perspective createPerspective1()
              {
                        System.out.println("\n createPerspective1() \n");
                  Perspective perspective = new Perspective("p1", "Perspective1");
                  LayoutSequence sequence = perspective.getInitialSequence(true);
                  return perspective;
              }
              private DemoPerspectiveFactory()
              {
              }
    }
    public ViewDemo3()
    {
        super("Viewport Demo",true,true,true,true);
        setSize(800,600);
        System.out.println("\n  view doem \n");
        configureDocking();
        boolean flag=true;
        if(flag){
              setContentPane(oldCreateContentPane());
              DockingManager.restoreLayout();
          }
            else
               setContentPane(createContentPane());
        setVisible(true);
    }
    private JPanel oldCreateContentPane()
      {
            System.out.println("\n oldCreateContentPane() \n");
            JPanel p = new JPanel(new BorderLayout(0, 0));
            p.setBorder(new EmptyBorder(5, 5, 5, 5));
            final View view1;
            final View view2;
            final View view3;
            final View view4;
            viewport = new Viewport();
            view1 = createView("solution.explorer", "Solution Explorer");
            view2 = createView("task.list", "Task List");
          view3 = createView("class.view", "Class View");
          view4 = createView("message.log", "Message Log");

          JToolBar jtb=new JToolBar();
                    JButton button = new JButton("UnLock",new ImageIcon("images/left.gif"));
                        button.setToolTipText("This is the left button");
                         button.addActionListener(new ActionListener() {
                          public void actionPerformed(ActionEvent e) {
                              view1.getDockingProperties().setDockingEnabled(true);
                              view2.getDockingProperties().setDockingEnabled(true);
                              view3.getDockingProperties().setDockingEnabled(true);
                              view4.getDockingProperties().setDockingEnabled(true);
                              view1.setActionBlocked("pin",true);
                              view2.setActionBlocked("pin",true);
                              view3.setActionBlocked("pin",true);
                              view4.setActionBlocked("pin",true);
                              view1.setActiveStateLocked(false);
                              view2.setActiveStateLocked(false);
                              view3.setActiveStateLocked(false);
                              view4.setActiveStateLocked(false);
                              view1.updateUI();
                              view2.updateUI();
                              view3.updateUI();
                              view4.updateUI();
                          }
                        });
                        jtb.add(button);
                        //second button
                        button = new JButton(new ImageIcon("images/middle.gif"));
                        button.setToolTipText("This is the middle button");
                        button.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                         }
                        });
                        jtb.add(button);

                        //third button
                        button = new JButton("Lock",new ImageIcon("images/right.gif"));
                        button.setToolTipText("This is the right button");
                        button.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                          //displayResult("Action for third button");
                              view1.getDockingProperties().setDockingEnabled(false);
                              view2.getDockingProperties().setDockingEnabled(false);
                              view3.getDockingProperties().setDockingEnabled(false);
                              view4.getDockingProperties().setDockingEnabled(false);
                              view1.setActionBlocked("pin",false);
                              view2.setActionBlocked("pin",false);
                              view3.setActionBlocked("pin",false);
                              view4.setActionBlocked("pin",false);
                              view1.setActiveStateLocked(true);
                              view2.setActiveStateLocked(true);
                              view3.setActiveStateLocked(true);
                              view4.setActiveStateLocked(true);
                         }
                        });
                    jtb.add(button);

        p.add(jtb,BorderLayout.NORTH);
            p.add(viewport, "Center");
            viewport.dock(view1);
            view1.dock(view2, "EAST");
            view2.dock(view3, "WEST");
            return p;
    }
    private JPanel createContentPane()
    {
            System.out.println("\n createContentPane() \n");
        JPanel p = new JPanel(new BorderLayout(0, 0));
        p.setBorder(new EmptyBorder(5, 5, 5, 5));
        final View view1;
        final View view2;
        final View view3;
        final View view4;
        viewport = new Viewport();
        view1 = createView("solution.explorer", "Solution Explorer");
        view2 = createView("task.list", "Task List");
        view3 = createView("class.view", "Class View");
        view4 = createView("message.log", "Message Log");
         JToolBar jtb=new JToolBar();
                    JButton button = new JButton("UnLock",new ImageIcon("images/left.gif"));
                        button.setToolTipText("This is the left button");
                         button.addActionListener(new ActionListener() {
                          public void actionPerformed(ActionEvent e) {
                              view1.getDockingProperties().setDockingEnabled(true);
                              view2.getDockingProperties().setDockingEnabled(true);
                              view3.getDockingProperties().setDockingEnabled(true);
                              view4.getDockingProperties().setDockingEnabled(true);
                              view1.setActionBlocked("pin",true);
                              view2.setActionBlocked("pin",true);
                              view3.setActionBlocked("pin",true);
                              view4.setActionBlocked("pin",true);
                              view1.setActiveStateLocked(false);
                              view2.setActiveStateLocked(false);
                              view3.setActiveStateLocked(false);
                              view4.setActiveStateLocked(false);
                              view1.updateUI();
                              view2.updateUI();
                              view3.updateUI();
                              view4.updateUI();
                          }
                        });
                        jtb.add(button);
                        //second button
                        button = new JButton(new ImageIcon("images/middle.gif"));
                        button.setToolTipText("This is the middle button");
                        button.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                        // displayResult("Action for second button");
                         }
                        });
                        jtb.add(button);
                        //third button
                        button = new JButton("Lock",new ImageIcon("images/right.gif"));
                        button.setToolTipText("This is the right button");
                        button.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                              view1.getDockingProperties().setDockingEnabled(false);
                              view2.getDockingProperties().setDockingEnabled(false);
                              view3.getDockingProperties().setDockingEnabled(false);
                              view4.getDockingProperties().setDockingEnabled(false);
                              view1.setActionBlocked("pin",true);
                              view2.setActionBlocked("pin",true);
                              view3.setActionBlocked("pin",true);
                              view4.setActionBlocked("pin",true);
                              view1.setActiveStateLocked(true);
                              view2.setActiveStateLocked(true);
                              view3.setActiveStateLocked(true);
                              view4.setActiveStateLocked(true);
                         }
                        });
                    jtb.add(button);

        p.add(jtb,BorderLayout.NORTH);
        p.add(viewport, "Center");
        viewport.dock(view1);
            view1.dock(view2, "EAST");
            view2.dock(view3, "WEST");
            return p;
    }
    private View createView(String id, String text)
    {
        View view = new View(id, text);
        view.addAction("close");
        view.addAction("pin");
        JPanel p = new JPanel();
        p.setBorder(new LineBorder(Color.GRAY, 1));
        JTextField t = new JTextField(text);
        t.setPreferredSize(new Dimension(100, 20));
        p.add(t);
        view.setContentPane(p);

        return view;
    }
    private static void configureDocking()
      {
                  System.out.println("\n *** bfr ViewFactory() ***  \n");
                  DockingManager.setDockableFactory(new ViewFactory());
              DockingManager.setFloatingEnabled(true);
              EffectsManager.setPreview(new GhostPreview());
              PerspectiveManager.setFactory(new DemoPerspectiveFactory());
              PerspectiveManager.setRestoreFloatingOnLoad(true);
              PerspectiveManager mgr = PerspectiveManager.getInstance();
              org.flexdock.perspective.persist.PersistenceHandler persister = new FilePersistenceHandler(new File(FilePersistenceHandler.DEFAULT_PERSPECTIVE_DIR, "PerspectiveDemo1.xml"), XMLPersister.newDefaultInstance());
              PerspectiveManager.setPersistenceHandler(persister);
              try
              {
                  DockingManager.loadLayoutModel();
              }
              catch(IOException ex)
              {
                  ex.printStackTrace();
              }
              catch(PersistenceException ex)
              {
                  ex.printStackTrace();
              }
        DockingManager.setAutoPersist(true);

    }
}


0
 
objectsCommented:
>  i am recreating the frame every time when i open it,

that may be the problem.
Theres no need to that is there? you can just use setVisible() to show/hide frame
0
 
krishnasaikarthikAuthor Commented:
ok, thanq.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now