JScrollPane 内的 JDesktopPane 调整大小问题

JDesktopPane inside JScrollPane resize issue

我在 JScrollPane 里面有一个 JDesktopPane。在 JDesktopPane 中有许多 JInternalFrames,以编程方式添加。我想要这种行为:

基本上每个图像编辑器(即 Photoshop)都具有相同的行为,但视口中有 JInternalFrames 而不是图像。

起初我认为这种行为很容易获得,但我不能完全正确。我肯定遗漏了一些关于布局或相关的东西......

这是相关的 SSCCE

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;
    }
}

JScrollPane 视口不考虑大小或边界,而是首选 大小。所以

class Main extends JFrame {

    private static final int DT_WIDTH = 1920;
    private static final int DT_HEIGHT = 1080;
    private JDesktopPane container = new JDesktopPane();

    public Main(){
        super("JDesktopPane SS");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(1280, 720);

        // setLayout(new ScrollPaneLayout()); // ?????

        // container.setBounds(new Rectangle(1920, 1080));
        container.setPreferredSize(new Dimension(DT_WIDTH, DT_HEIGHT));