问题
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