When I call pack()
on a JInternalFrame
it is not packed correctly, mostly too tight.
Edit:
Here is a minimal example that shows the behavior described above. It also seems to depend on the used lookandfeel (here: Nimbus).
import javax.swing.*;
public class JInternalFrameTester {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
System.err.println("Failed setting NimbusLookAndFeel");
}
JFrame frame = new JFrame();
JDesktopPane desktop = new JDesktopPane();
desktop.setOpaque(true);
frame.setContentPane(desktop);
frame.setSize(250, 250);
frame.setVisible(true);
JInternalFrame iframe = new JInternalFrame("Internal Frame");
JTextField textfield = new JTextField("Any text here");
iframe.add(textfield);
iframe.setVisible(true);
/* XXX If placed here, it crashes the layouts */
iframe.pack();
desktop.add(iframe);
/* XXX If placed here, the layout is right */
//iframe.pack();
}
}
将JInternalFrame
添加到相应的JDesktopPane
之后,必须调用pack()
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.