<commit_before>//
// $Id: SafeScrollPane.java,v 1.4 2002/10/06 20:57:36 mdb Exp $

package com.threerings.media;

import java.awt.Component;

import javax.swing.JScrollPane;
import javax.swing.JViewport;

/**
 * A scroll pane that is safe to use in frame managed views.
 */
public class SafeScrollPane extends JScrollPane
{
    public SafeScrollPane ()
    {
    }

    public SafeScrollPane (Component view)
    {
        super(view);
    }

    protected JViewport createViewport ()
    {
        JViewport vp = new JViewport();
        vp.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
        return vp;
    }
}
<commit_msg>When the JViewport scrolls its components, it simply calls setLocation() which results in the component (and every other component in between that component and the Sun) becoming invalid. Unfortunately, it isn't kind enough to also let the RepaintManager know about its jokey business, and so things simply remain invalid until some other joker comes along and invalidates everything on God's green earth (like the JTextField). We hack in a call to revalidate() on our poor unsuspecting scrolled component so that everything will work properly.<commit_after>//
// $Id: SafeScrollPane.java,v 1.5 2002/11/05 05:51:18 mdb Exp $

package com.threerings.media;

import java.awt.Component;
import java.awt.Point;

import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JViewport;

/**
 * A scroll pane that is safe to use in frame managed views.
 */
public class SafeScrollPane extends JScrollPane
{
    public SafeScrollPane ()
    {
    }

    public SafeScrollPane (Component view)
    {
        super(view);
    }

    protected JViewport createViewport ()
    {
        JViewport vp = new JViewport() {
            public void setViewPosition (Point p) {
                super.setViewPosition(p);
                // simple scroll mode results in setViewPosition causing
                // our view to become invalid, but nothing ever happens to
                // queue up a revalidate for said view, so we have to do
                // it here
                Component c = getView();
                if (c instanceof JComponent) {
                    System.out.println("Revalidating " + c);
                    ((JComponent)c).revalidate();
                }
            }
        };
        vp.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
        return vp;
    }
}

{'fraction_non_alphanumeric': 0.07927332782824112, 'fraction_numerical': 0.013212221304706853, 'mean_word_length': 2.4963924963924966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1364055', 'n_tokens_mistral': 709, 'n_tokens_neox': 664, 'n_words': 234}