As we know JInternalFrame cannot run..we have to set it to a JDesktopPane But I heard from one of my friends that JInternalFrame can run. Is that possible..? Is there any code for main method ...?
Asked
Active
Viewed 701 times
0
-
1You need to specify exactly what you are trying to do, and also preferably what you've tried so far. – Birb Nov 18 '13 at 06:44
-
1As far as I know, there's no way to run `JInternalFrame` without adding it into a `JDesktopPane`. Try running the JIF on a JFrame for the main method to have a view the layout. – David B Nov 18 '13 at 06:58
-
1better could be without !, for better help sooner post an SSCCE, short, runnable, compilable, without any shouting !!! – mKorbel Nov 18 '13 at 07:10
1 Answers
1
Sure, “JInternalFrame cannot run”; they don’t have legs. But if you claim that they cannot be used without a JDesktopPane
, where do you get that “knowledge” from? And why don’t you try for yourself? It takes less than five minutes:
import javax.swing.*;
public class IFrames
{
public static void main(String[] args)
{
try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }
catch(Exception ex){}
JFrame f=new JFrame();
f.setContentPane(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
createFrame("Left"), createFrame("right") ));
f.setSize(300, 300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
private static JInternalFrame createFrame(String title)
{
final JInternalFrame f1 = new JInternalFrame(title, true, true);
f1.setVisible(true);
f1.getContentPane().add(new JLabel(title));
return f1;
}
}
Simple answer: no one prevents you from using them without a JDesktopPane
though using them with it is more natural. The documentation says: “Generally, you add JInternalFrames to a JDesktopPane.”
Well, “Generally” does not preclude exemptions.
By the way JOptionPane.showInternal…Dialog
is a typical example of an application of using a JInternalFrame
without a JDesktopPane
.

Holger
- 285,553
- 42
- 434
- 765
-
+1 for `JOptionPane.showInternal*Dialog`; a related example is cited [here](http://stackoverflow.com/a/19905717/230513). – trashgod Nov 18 '13 at 11:17
-
-
1@zIronManBox: *internal* frames need an ancestor, whether it is a `Window`, `Frame` or `Dialog` doesn’t matter. If all you are interested in, is showing it without surrounding decoration, setting the `JInternalFrame` as content pane of a `JWindow` would do, though for most use cases, you’d better use a `JFrame` or `JDialog` plus `setUndecorated(true);`. Keep in mind that the internal frame’s controls will not control the host window. Maybe, you actually want [look&feel decorated](https://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.html#setDefaultLookAndFeelDecorated-boolean-) frames. – Holger Jun 13 '16 at 09:40
-
Yes, thanks for the response. I wanted to understand if internal frame could control the host window. Now I know. – zIronManBox Jun 13 '16 at 13:22