Swing JPanel Resizing: won't fit the contents of text file - cuts out text
<p>The java application I'm building utilises the Swing framework. I'm new to Swing, and I'm trying to display some text from a file. The problem is that not all my text is displayed using the code below - it is cut off.</p>

<p><strong>The code</strong></p>

<p>So far, I've created a JFrame component to contain everything:</p>

<pre><code>//initial frame that holds everything
frame = new JFrame(WINDOW_NAME);
frame.setSize(new Dimension((SCREEN_WIDTH.intValue()/100)*80, (SCREEN_HEIGHT.intValue()/100)*80));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
</code></pre>

<p>Within that, I've created a scroll pane to allow the user to read through the contents of the text file by scrolling vertically; it's quite a large text file - a few chapters from a book.</p>

<pre><code>JScrollPane scrollPane = new JScrollPane(contentPane);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setWheelScrollingEnabled(true);

frame.setContentPane(scrollPane);
</code></pre>

<p>The scroll pane contains a JPanel object. I've utilised the <strong>GridBagLayout</strong> layout manager for this. The panel itself holds an EditorPane which I've instantiated with the text file's URL.</p>

<pre><code>JPanel contentPane = new JPanel();
contentPane.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight()));

buildAndAddComponentsToFrame(contentPane);

private void buildAndAddComponentsToFrame(Container container) {

    container.setLayout(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();


    c.fill = GridBagConstraints.BOTH;
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.insets = new Insets((frame.getHeight()/100)*10, (frame.getWidth()/100)*10, (frame.getHeight()/100)*10, (frame.getWidth()/100)*10);

    //create a non-editable editor pane to hold the contents of the religious texts
    JEditorPane textContainer = new JEditorPane();
    textContainer.setEditable(false);

    //TODO load the content of the pane from a URL (local)

    File textFile = new File(*my text file*);   
    try {
        textContainer.setPage(textFile.toURI().toURL());
    } catch (IOException e) {
        e.printStackTrace();
    }

    container.add(textContainer,c);
}
</code></pre>

<p>This works - I'm able to read the contents of the file but not in its entirety: it only shows what it can fit within the height of the JPanel object. I don't want to place the text content within a ScrollPane - but make the JPanel's height be relative to the contents of the text file.</p>

<p>Is there any way to achieve this? I've used the container to make the "text area" appear like a microsoft word document hence the insets - it looks like a paper document in the middle of the jframe - this is intentional. </p>

<p>Thanks for any help - sorry if my explanation was a bit vague. I've added a screenshot to help explain.</p>

<p><a href="https://i.stack.imgur.com/5fPy1.png" rel="nofollow"><img src="https://i.stack.imgur.com/5fPy1.png" alt="screen shot of GUI"></a></p>