Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-10-2008, 08:33 PM
rad rad is offline
Member
 
Join Date: Aug 2008
Posts: 4
Rep Power: 0
rad is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 08-10-2008, 09:32 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,483
Rep Power: 8
Fubarable is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-10-2008, 09:41 PM
rad rad is offline
Member
 
Join Date: Aug 2008
Posts: 4
Rep Power: 0
rad is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-10-2008, 11:12 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,483
Rep Power: 8
Fubarable is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-11-2008, 01:23 AM
Member
 
Join Date: Aug 2008
Location: The Netherlands
Posts: 25
Rep Power: 0
Rooneyz is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-11-2008, 01:38 AM
rad rad is offline
Member
 
Join Date: Aug 2008
Posts: 4
Rep Power: 0
rad is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 08-11-2008, 02:45 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,483
Rep Power: 8
Fubarable is on a distinguished road
Default
While I don't know how a JInternalFrame can be dragged out easily, its content can be popped out pretty easily. For instance:
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();
      }
    });
  }
}
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 08-11-2008, 03:28 AM
rad rad is offline
Member
 
Join Date: Aug 2008
Posts: 4
Rep Power: 0
rad is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 08-11-2008, 03:33 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,483
Rep Power: 8
Fubarable is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
'cmd' is not recognized as an internal or external command thelukestir New To Java 6 07-30-2008 04:50 AM
Internal Frame order and canvas Z Index dazza-s New To Java 3 05-29-2008 07:20 AM
Eclipse's internal Tomcat vadimf Eclipse 0 02-14-2008 10:37 AM
an internal error occurred during refresh christina Eclipse 1 08-06-2007 10:37 PM
Description the server encountered an internal error Jack Enterprise JavaBeans 2 07-02-2007 03:24 AM


All times are GMT +2. The time now is 10:30 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org