[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.newcomer] Re: Getting scroll pane to display bottom of text (using Swing)
|
In article <dj5dnq$2tl$1@xxxxxxxxxxxxxxxx>, yaofahua@xxxxxxxxxxx (JACK
YAO) wrote:
> *From:* JACK YAO <yaofahua@xxxxxxxxxxx>
> *Date:* Wed, 19 Oct 2005 20:21:28 +0800
>
> Peter:
> you needn't use other JScrollPane methods if you only want to display
> the lastest text.The following is an example:
>
> **************************************************************
> public class test extends JFrame implements ActionListener {
>
> JTextArea ta;
> int i = 0;
>
> public test() {
> ta = new JTextArea(10,10);
> JScrollPane sp = new JScrollPane(ta);
> this.add(sp);
> JButton btn = new JButton("test");
> btn.addActionListener(this);
> this.add(btn,BorderLayout.NORTH);
> pack();
> setVisible(true);
> }
>
> public void actionPerformed(ActionEvent e) {
> ta.append("line :"+(i++)+"\n");
> }
> public static void main(String[] args) {
> new test();
> }
>
> }
> ****************************************************************
> Hope you will solve your problem.
>
> --
> JACK YAO, Beijing, China
>
Well, your code works fine. But even if I comment out the
scrollRectToVisible line it still doesn't put the slider at the bottom.
And I can't see any essential difference between your code and mine, apart
from the fact that my JScrollPane is inside an inner pane, while yours is
in the main frame - but surely this shouldn't make any difference? I'll
play around tomorrow (it's UK time here so getting late) and see what
happens.
Peter