JFrame.MAXIMIZED_BOTH höhe und breite abfragen

Das JLayeredPane kann etwas störrisch und un-intuitiv sein. Man kann mehrere Components hinzufügen, aber die liegen alle konzeptuell auf der gleichen Ebene. D.h. man kann für deinen Fall keinen vernünftigen layout manager setzen.

Eine Möglichkeit ist hier mal angedeutet:

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

public class Studieren
{
    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(() -> createAndShowGui());
    }

    private static void createAndShowGui()
    {
        Studieren test = new Studieren();
    }

    Studieren()
    {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new BorderLayout());

        String fileName = 
            "C:/Users/User/Desktop/El_jardín_de_las_Delicias,_de_El_Bosco.jpg";
        ImageComponent imageComponent = new ImageComponent(fileName);
        JScrollPane scrollPane = new JScrollPane(imageComponent);
        frame.add(scrollPane, BorderLayout.CENTER);

        // You should NOT use the null-layout here. But this is
        // done in order to place the "Test-B...". 
        imageComponent.setLayout(null);
        JButton button = new JButton("Test-Button");
        button.setBounds(50, 50, 80, 80);
        button.setBackground(Color.RED);
        imageComponent.add(button, new Integer(1));
        
        frame.setBounds(getMaximumWindowBounds());
        frame.setVisible(true);
    }
    
    
    static class ImageComponent extends JPanel
    {
        private final BufferedImage image;
        public ImageComponent(String fileName)
        {
            this.image = readImage(fileName);
        }
        @Override
        protected void paintComponent(Graphics g)
        {
            super.paintComponent(g);
            g.drawImage(image, 0, 0, null);
        }
        @Override
        public Dimension getPreferredSize()
        {
            return new Dimension(image.getWidth(), image.getHeight());
        }
    }
    
    private static BufferedImage readImage(String fileName)
    {
        try
        {
            return ImageIO.read(new File(fileName));
        }
        catch (IOException e)
        {
            throw new UncheckedIOException(e);
        }
    }

    private static Rectangle getMaximumWindowBounds()
    {
        GraphicsEnvironment graphicsEnvironment = 
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        return graphicsEnvironment.getMaximumWindowBounds();
    }

}

Etwas ähnliches hatte L-exctron-X kürzlich auch gepostet. Und in ImageComponent - eine JComponent, um ein BufferedImage anzuzeigen bin ich da mal noch ein paar Schritte weitergegangen…

Danke für die Hilfe!