Reputation: 11
I have a problem; I hope you can help me :)
I want to refresh a JScrollPane. I wrote a sample programme that shows what I would like to do:
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
public class ScrollEx extends JFrame{
private static final long serialVersionUID = 1L;
private JPanel panel = new JPanel();
private JTextArea area = new JTextArea(15, 20);
private JScrollPane scroll = new JScrollPane(area);
public ScrollEx(){
super("JScrollPane Test!");
setSize(300, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
this.panel.setSize(300, 300);
this.panel.add(scroll);
for(Integer i = 0; i <= 50; i++){
this.area.append(i.toString() + "\n");
}
getContentPane().add(panel);
setVisible(true);
}
public static void main(String [] args){
new ScrollEx();
}
}
The preceding code shows a simple programme that prints out the numbers from 0 to 50 on a JTextArea
. However, this printing exceeds the bounds of the JTextArea
and the JScrollPane
doesn't refresh by itself. So my question is, what can I do to refresh the JScrollPane
and make it dynamic in order to show the whole list of numbers?
Upvotes: 1
Views: 398
Reputation: 324098
However, this printing exceeds the bounds of the JTextArea and the JScrollPane doesn't refresh by itself
All the data is displayed. If you mean you want the scrollpane to automatically scroll to see the last line added then check out Text Area Scrolling for an explanation on what is happening and a solution.
Upvotes: 2