Results 1 to 9 of 9
  1. #1
    rad
    rad is offline Member
    Join Date
    Aug 2008
    Posts
    4
    Rep Power
    0

    Default Getting internal frame out

    Hello Guys,
    I'm brand new to Java and to this forum as well ,
    I have a question , how can I get an internal frame outside the main frame , You can call it pop out ,tear off ,floating window .. or whatever you want .
    I'm using this example
    java.sun.com/docs/books/tutorial/uiswing/events/internalframelistener.html

    Thank you very much in advance.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Perhaps I don't understand you, but from what I gather, are you trying to turn an JInternalFrame into a free-standing dialog? If so, that would take some doing. I suppose that you could extract the contentPane from an internal frame and place it into a JDialog. If you wish to do this, I have to ask why? If you don't, I will then ask you to clarify your problem.

    Best of luck.

  3. #3
    rad
    rad is offline Member
    Join Date
    Aug 2008
    Posts
    4
    Rep Power
    0

    Default

    Hi Fubarable ,
    Thanks for your reply. What I'm trying to do, is just to be able to drag the internal frame and place it outside the main ( Jframe ) frame , that's all .
    Please remember I'm newbie to java.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I could be wrong, but I don't think that this is possible. The JInternalFrame is called "internal" for a reason. If you want something external to the JFrame, you'll have to use something built for this such as a JDialog.

  5. #5
    Rooneyz is offline Member
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    25
    Rep Power
    0

    Default

    Maybe a secondary JFrame will be a solution for your problem? You can place all the things you want on your second frame. Or am I on the wrong track?

  6. #6
    rad
    rad is offline Member
    Join Date
    Aug 2008
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by Rooneyz View Post
    Maybe a secondary JFrame will be a solution for your problem? You can place all the things you want on your second frame. Or am I on the wrong track?
    ,
    No, you are not on the wrong track , but I cannot apply this method as I have to change all the listeners too and maybe other things too . ( What I'm trying to do is to modify a huge project that has tens of internal frames , I want to get all/some of them outside the main Jframe , so I can distribute them on my screens the way I want , without changing the behavior of the them ) .
    I was thinking it could be a parameter I add to the internal frame, that can let me drag it out of the main frame. or pop it out . ,but seems there is no way. :(

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    While I don't know how a JInternalFrame can be dragged out easily, its content can be popped out pretty easily. For instance:
    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.BorderFactory;
    import javax.swing.ButtonGroup;
    import javax.swing.JButton;
    import javax.swing.JDesktopPane;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    import javax.swing.JTextField;
    
    public class PopInternalOut
    {
      private static final String POP_OUT = "Pop Panel Out";
      private static final String PUSH_BACK = "Push Panel Back";
      private JPanel mainPanel = new JPanel(new BorderLayout());
      private JPanel popablePanel;
      private JButton popOutBtn = new JButton(POP_OUT);
      private JDesktopPane desktopPane = new JDesktopPane();
      private JInternalFrame internalFrame = new JInternalFrame("Internal Frame", false);
      private JDialog dialog;
    
      public PopInternalOut(JFrame frame)
      {
        JPanel buttonPanel = new JPanel();
        popOutBtn.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent e)
          {
            popOutAction(e);
          }
        });
        buttonPanel.add(popOutBtn);
        
        desktopPane.setBorder(BorderFactory.createLineBorder(Color.black));
        popablePanel = createPopablePanel();
        internalFrame.setContentPane(popablePanel);
        internalFrame.pack();
        desktopPane.add(internalFrame);
        internalFrame.setVisible(true);
        
        dialog = new JDialog(frame, "Dialog", false);
        
        mainPanel.setPreferredSize(new Dimension(800, 600));
        mainPanel.add(desktopPane, BorderLayout.CENTER);
        mainPanel.add(buttonPanel, BorderLayout.SOUTH);
      }
    
      private JPanel createPopablePanel()
      {
        JPanel pp = new JPanel();
        pp.setPreferredSize(new Dimension(300, 300));
        pp.setLayout(new GridLayout(3, 0, 0, 0));
        ButtonGroup btngrp = new ButtonGroup();
        for (int i = 0; i < 6; i++)
        {
          JRadioButton rBtn = new JRadioButton("RadioBtn " + i);
          btngrp.add(rBtn);
          pp.add(rBtn);
        }
        String[] textStrings = 
        {
          "Hello", "Goodbye", "Whatever"
        };
        for (int i = 0; i < textStrings.length; i++)
        {
          JTextField textField = new JTextField(8);
          textField.setText(textStrings[i]);
          JPanel tfPanel = new JPanel();
          tfPanel.add(textField);
          pp.add(tfPanel);
        }
        return pp;
      }
    
      private void popOutAction(ActionEvent e)
      {
        JButton sourceBtn = (JButton)e.getSource();
        if (e.getActionCommand().equals(POP_OUT))
        {
          sourceBtn.setText(PUSH_BACK);
          sourceBtn.setActionCommand(PUSH_BACK);
          JPanel panel = (JPanel) internalFrame.getContentPane();
          internalFrame.setVisible(false);
          dialog.setContentPane(panel);
          dialog.pack();
          dialog.setVisible(true);
        }
        else if (e.getActionCommand().equals(PUSH_BACK))
        {
          sourceBtn.setText(POP_OUT);
          sourceBtn.setActionCommand(POP_OUT);
          JPanel panel = (JPanel) dialog.getContentPane();
          dialog.setVisible(false);
          internalFrame.setContentPane(panel);
          internalFrame.pack();
          internalFrame.setVisible(true);
        }
      }
    
      public JPanel getMainPanel()
      {
        return mainPanel;
      }
    
      private static void createAndShowUI()
      {
        JFrame frame = new JFrame("PopInternalOut");
        frame.getContentPane().add(new PopInternalOut(frame).getMainPanel());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    
      public static void main(String[] args)
      {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
          public void run()
          {
            createAndShowUI();
          }
        });
      }
    }

  8. #8
    rad
    rad is offline Member
    Join Date
    Aug 2008
    Posts
    4
    Rep Power
    0

    Default

    Fubarable, Thank you very much for the code , I've compiled it, and it works great.
    I still have to figure out how to use it with more than one internal frame, and how use it with an existing project with so many internal fames. Still newbie to Java as I said, so will need some time to find my way around
    Thank you very much, I appreciate your help.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    It is better to code to the JPanel rather than to the JInternalFrame, JFrame, or JApplet. The bottom line as I see it is to code with flexibility in mind. If I program with the idea that I'm going to create a JPanel, then if desired this JPanel can be placed in a JInternalFrame, or JFrame, JDialog, or other JPanel or any other place desired.

Similar Threads

  1. Replies: 6
    Last Post: 07-30-2008, 03:50 AM
  2. Internal Frame order and canvas Z Index
    By dazza-s in forum New To Java
    Replies: 3
    Last Post: 05-29-2008, 06:20 AM
  3. Eclipse's internal Tomcat
    By vadimf in forum Eclipse
    Replies: 0
    Last Post: 02-14-2008, 09:37 AM
  4. an internal error occurred during refresh
    By christina in forum Eclipse
    Replies: 1
    Last Post: 08-06-2007, 09:37 PM
  5. Description the server encountered an internal error
    By Jack in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 07-02-2007, 02:24 AM

Posting Permissions

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