JLink
JLink

Reputation: 307

View JInternalFrames without JDesktopPanes

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 ...?

Upvotes: 0

Views: 732

Answers (1)

Holger
Holger

Reputation: 298123

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.

Upvotes: 1

Related Questions