View JInternalFrames without JDesktopPanes

北城以北 提交于 2019-12-25 04:53:07

问题


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


回答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.



来源:https://stackoverflow.com/questions/20041622/view-jinternalframes-without-jdesktoppanes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!