开发者

updating view only after changing the size of JFrame

So I have a JFr开发者_Go百科ame in which inside of it I have a JScrollPane and inside the JScrollPane I have a JPanel. I have a button click mouse listener that modifies the JPanel inside the JScrollPane. The code in the mouse listener is:

@Override
    public void mouseClicked(MouseEvent arg0) {

            searchResult.updateInfo();

        }

The method updateInfo is adding a bunch of JPanel into the searchResult JPanel. After I click the button associated with this listener, nothing happens, but when I resize the JFrame.. it updates the view.. why is this?

I tried repaint the JFrame, but it did not solve my problem


After adding/removing components from a visible GUI you need to tell the panel to layout the components so the preferred size can be recalculated. You need to add:

searchResult.revalidate();
searchResult.repaint(); // sometimes needed

Then if the preferred size is greater than the size of the scrollpane scrollbars will appear.


make searchResult.removeAll(); searchResult.updateInfo(); searchResult.validate(); if it doesn't work make like this searchResult.removeAll(); searchResult.updateInfo(); searchResult.validate(); searchResult.repaint();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜