
08-10-2008, 08:33 PM
|
|
Member
|
|
Join Date: Aug 2008
Posts: 4
Rep Power: 0
|
|
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.
|
|

08-10-2008, 09:32 PM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,483
Rep Power: 8
|
|
|
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.
|
|

08-10-2008, 09:41 PM
|
|
Member
|
|
Join Date: Aug 2008
Posts: 4
Rep Power: 0
|
|
|
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.
|
|

08-10-2008, 11:12 PM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,483
Rep Power: 8
|
|
|
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.
|
|

08-11-2008, 01:23 AM
|
|
Member
|
|
Join Date: Aug 2008
Location: The Netherlands
Posts: 25
Rep Power: 0
|
|
|
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?
|
|

08-11-2008, 01:38 AM
|
|
Member
|
|
Join Date: Aug 2008
Posts: 4
Rep Power: 0
|
|
Originally Posted by Rooneyz
|
|
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.
|
|

08-11-2008, 02:45 AM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,483
Rep Power: 8
|
|
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();
}
});
}
} |
|
|

08-11-2008, 03:28 AM
|
|
Member
|
|
Join Date: Aug 2008
Posts: 4
Rep Power: 0
|
|
|
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.
|
|

08-11-2008, 03:33 AM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,483
Rep Power: 8
|
|
|
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.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +2. The time now is 10:30 AM.
|
|