Have to move screen to get JTextArea to appear

I have a desktop pane program where a user inputs data and a jtextarea appears with their results. Instead of having just the text area, i wanted to add it to a scroll pane, which i did. So I created a new scroll pane, and added the text area to it. Now, when I put in data the text area in the scroll pane does not appear until I move the page. In other words, everything works, but I have to move the page a little in order for the results and the scroll pane to show up on the screen.

Any ideas on why this is happening?

 private JTextArea matchListResults = new JTextArea();
 private JPanel matchPanelBase = new JPanel(new BorderLayout());
 private JScrollPane mResults = new JScrollPane();

    private void matchResFrame(String[] matchResultArray) throws IOException,          SQLException {

        Dimension size = new Dimension();
        size.setSize(400, 300);
        matchListResults.setPreferredSize(size);
        matchListResults.setFont(font);

. . .

        mResults.getViewport().add(matchListResults);
        matchListResults.setVisible(true);
        matchPanelBase.add(mResults, BorderLayout.CENTER);
    }

Answers


When you add components to a visible GUI the basic code is:

panel.add(...);
panel.revalidate();
panel.repaint();

By default all components have a size of (0, 0) so there is nothing to paint. The revalidate() will invoke the layout manager which will determine the components size and location.


After you add the new components, call repaint() on the panel.

matchPanelBase.repaint();

Need Your Help

Dynamically hide/show textboxs when a checkbox clicked

javascript jquery html

After a bit of JQ research, I updated the question because it upset some, rightly, hands-up! When a checkbox is clicked content of corresponding should be visible and vice verse. How can I do it?

How to save trace info into a file

asp.net web-config trace

I am tracing my ASPX page by enabling tracing in web.config (<trace enabled="true" pageOutput="true"/>)

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.