Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2155

Re: JScrollBar problems

From "Roedy Green" <roedy.green@THRWHITE.remove-dii-this>
Subject Re: JScrollBar problems
Message-ID <6odja3ltmng762sj2e58una7e9cq8419n7@4ax.com> (permalink)
Newsgroups comp.lang.java.gui
References <9pbja39frohr5idpvcvnsd1ln3qbgm2tfl@4ax.com>
Date 2011-04-27 15:37 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
>I am trying to force the scrolling to show the top of what I have just
>generated in a JTextArea.
>
> JTextArea  howTo =
>                new JTextArea(  ... );
>        howTo.setForeground( BLACK );
>        howTo.setMargin( new Insets( 5, 5, 5, 5 ) );
>        howToScroller =
>                new JScrollPane( howTo,
> JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
> JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
>                         );
>....
>
>             howTo.setText( ...  );
>
>            // make sure top of generated code is visible.
>            final JScrollBar v = howToScroller.getVerticalScrollBar();
>            v.setValue( v.getMinimum() );
>
>Yet it ignores me. It acts as if I had said v.getMaximum() showing the
>END of the text instead of the beginning.

mystery solved.  This might be considered a bug in sun.

There is how I got it to work:

  // invoke later to give time for text to render.
            SwingUtilities.invokeLater( new Runnable() {
                public void run()
                    {
                    final JScrollBar v =
howToScroller.getVerticalScrollBar();
                    v.setValue( v.getMinimum() );
                    }
            } );
The key is, the setText had to RENDER before the setValue was
processed. 
-- 
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

JScrollBar problems "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
  Re: JScrollBar problems "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
    Re: JScrollBar problems "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
  Re: JScrollBar problems "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
    Re: JScrollBar problems "Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
      Re: JScrollBar problems "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
        Re: JScrollBar problems "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000

csiph-web