Hi all,
I have a problem with a JScrollPane and a JPanel:
- If I fill the panel with 100 buttons, the scroll position is at the top
- If in the same panel I fill with 100 JTextAreas, the scroll position is at the bottom
package testing.scrollablePanel;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import org.jdesktop.swingx.VerticalLayout;
public class TestScrollablePanel {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JPanel panel = new JPanel(new VerticalLayout());
for (int i = 0; i < 100; i++) {
// panel.add(new JButton("Hello there my friend"));
panel.add(new JTextArea("Hello there my friend"));
}
JScrollPane scrollPane = new JScrollPane(panel);
JFrame frame = new JFrame();
frame.getContentPane().add(scrollPane);
frame.setPreferredSize(new Dimension(300, 300));
frame.pack();
frame.setVisible(true);
}
});
}
}
Now, how can I make the JTextArea behave as the JButton (i.e. leave the scroll to the top?
Thanks in advance