JDesktopPane
a内部
JScrollPane
JDESKTOPANE公司
JInternalFrame
s、 以编程方式添加。我希望有这样的行为:
与每个图像编辑器(即Photoshop)的行为基本相同,但
内部框架
s而不是图像。
起初我以为这种行为很容易发生,但我不能完全正确。当然我错过了一些关于布局或相关的东西。。。
import javax.swing.*;
import java.awt.Dimension;
import java.awt.Rectangle;
class Main extends JFrame {
JDesktopPane container = new JDesktopPane();
// New frame with 2 JInternalFrames inside a JDesktopPane inside a JScrollPane
Main(){
super("JDesktopPane SS");
setSize(1280, 720);
setLayout(new ScrollPaneLayout());
container.setBounds(new Rectangle(1920, 1080));
JScrollPane scrollContainer = new JScrollPane(container, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
setContentPane(scrollContainer);
container.add(createFrame());
container.add(createFrame());
}
public static void main(String[] args){
SwingUtilities.invokeLater(() -> {
// Create new frame with 2 JInternalFrames inside a JDesktopPane inside a JScrollPane
JFrame main_frame = new Main();
main_frame.setVisible(true);
});
}
// Create new InternalFrame with a TextPane
private JInternalFrame createFrame(){
JInternalFrame new_frame = new JInternalFrame("Document");
new_frame.setResizable(true);
JTextPane txt = new JTextPane();
txt.setPreferredSize(new Dimension(100, 80));
new_frame.add(txt);
new_frame.pack();
new_frame.setVisible(true);
return new_frame;
}
}