JScrollpane does not autoresize when there is a JTable inside. Work around?
<p>It has been identified as a possible duplicate of the question:</p>

<p><a href="https://stackoverflow.com/questions/33433485/jpanel-window-not-scaling-when-resize-the-main-frame">JPanel Window not scaling when resize the main frame</a></p>

<p>I do not agree, because at that topic the problem is that the JPanel does not resize. In my case, the JPanel has no problems, but the JScrollPane is not getting resized!</p>

<p>I have a <code>JFrame</code>, there is a <code>JPanel</code> inside, containing a <code>JScrollpane</code>, which contains a <code>JTable</code>.</p>

<p>The problem is, that if the <code>JFrame</code> is resized, the <code>JScrollpane</code> stays the same, doesn't matter if the <code>JFrame</code> is made really small, so that the scroll pane does not even fit in the window or really big. </p>

<p>I want to make the <code>JScrollpane</code> adjust itself according to its <code>JPanel</code>, which gets adjusted by resizing of the window.
If the same thing is done by using a <code>JTextArea</code> inside the <code>JScrollPane</code>, everything works just fine -- resizing the <code>JPanel</code> resizes the scroll pane.</p>

<p>Do you have any idea why the <code>JTable</code> ruins the automatic resizing of the <code>JScrollPane</code>, and how to get around it? It seems, that the <code>LayoutManager</code> somehow is not able to handle it properly... (I also tried to add images showing what's happening, but I still don't have enough of reputation...)</p>

<p>Here is the code:</p>

<pre><code>JFrame tableFrame = new JFrame("Test Table");
editPanel vadEditPane;
vadEditPane = new editPanel(vadData);
vadEditPane.setOpaque(true); //content panes must be opaque
tableFrame.getContentPane().add(vadEditPane, BorderLayout.CENTER);

public class editPanel extends JPanel {
    public editPanel(dataConv vadData){
        JTable vadTable;
        String[] columnNames = {---SOME COLUMN NAMES---};
        Object[][] data = {---SOME DATA---};
        vadTable = new JTable(data, columnNames);
        vadTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
        vadTable.setFillsViewportHeight(true);
        vadTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        JScrollPane scrollPane = new JScrollPane(vadTable);
        scrollPane.setBackground(Color.RED);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        add(scrollPane);
        setBackground(Color.ORANGE); 
        }
    }
</code></pre>