I created a JScrollPane with a JTable on it. When the table's height is larger than the height of the scroll pane, a scroll bar appears. If minimize the JFrame although I didn't change the size of it, the scroll bar vanishes and the scroll pane extends downwards.
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class Main {
    
    static String columns[] = {"Date", "Price", "URL", "Expired"};
    static String data[][] = new String[8][4];
    
    /*
     * The data that should be provided to the JTable is 
     * replaced with some example data because the method
     * of getting this data is complicated and doesn't
     * change anything at the outcome.
     */
    public static void main(String[] args) {
        
        loadGui();
    }
    
    public static void loadGui() {
        
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 4; j++) {
                data[i][j] = "Example data " + i + " " + j;
            }
        }
        
        JFrame mainFrame = new JFrame();
        mainFrame.setSize(800, 300);
        mainFrame.setResizable(false);
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainFrame.setVisible(true);
        
        JTable table = new JTable(data, columns);;
        table.setPreferredScrollableViewportSize(table.getPreferredSize());
        
        JScrollPane pane = new JScrollPane(table);
        pane.setViewportView(table);
        pane.setSize(785, 100);
        mainFrame.add(pane);
        table.getTableHeader().setReorderingAllowed(false);
        table.setDefaultEditor(Object.class, null);
        table.setFocusable(false);
        table.setRowSelectionAllowed(false);
    }
}
I search for a way to stop the scroll pane to extend downwards and keeping it in its size.