0
I have a screen with a JSrollPane and several JTextFields. When I change textfield using the key tab, the JScrollPane does not track if the textfield that receives the focus is "below the screen".
I wanted that when I changed the focus to a textfield that is not appearing, the JScrollPane accompany and descend or rise depending on which textfield I change focus to.
Code to generate the screen, is a very simple screen only with the same textfield:
package newpackage;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
public class GridLayoutButtonsTest extends JFrame {
    private JPanel contentPane;
    private int qtButton = 0;
    public static void main(String[] args) {
        GridLayoutButtonsTest frame = new GridLayoutButtonsTest();
        frame.setVisible(true);
    }
    public GridLayoutButtonsTest() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setPreferredSize(new Dimension(500, 200));
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        JScrollPane scroll = new JScrollPane();
        scroll.setPreferredSize(new Dimension(464, 139));
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 1, 10, 10));
        for (int i = 0; i < 15; i++) {
            panel.add(gerarField());
        }
        scroll.setViewportView(panel);
        contentPane.add(scroll);
        pack();
    }
    public JTextField gerarField() {
        qtButton++;
        JTextField NewField = new JTextField(String.valueOf(qtButton));
        return NewField;
    }
}
