Re: JScrollPane vertical bar is defaulting to the bottom



Debs schrieb:
Hi,

I have a JScrollPane for a large panel, when it displays the vertical
bar is at the bottom. I want it at the top - I have various other
JScrollPanes elsewhere that default to the top as expected.

I believe the difference may be that this panel contains JTextAreas,
and I have read that setting the caret position can help. However, with
it having multiple, I'm not sure what to do. I have tried setting the
focus and caret position in the first JTextArea, but this did not work.

A few days ago someone asked the same in c.l.j.programmer - but for the horizontal direction.

The behaviour is caused by JComponent that reaches scrollRectToVisible up the component tree. Knowing this, the solution is obvious: just intercept the chain.

To intercept the chain you'd have to put JTextArea into a container that implements it's own version of scrollRectToVisible. E.g. a JViewport or another panel that overrides this method.

So the solution for the code you gave in your previous post is simple:

JPanel innerDetailPanel = new JPanel(new GridBagLayout()) {
public void scrollRectToVisible( Rectangle r ) {}
};

Bye
Michael


.



Relevant Pages

  • Re: JScrollPane vertical bar is defaulting to the bottom
    ... I have a JScrollPane for a large panel, ... I believe the difference may be that this panel contains JTextAreas, ... focus and caret position in the first JTextArea, ... intercept the chain. ...
    (comp.lang.java.gui)
  • Re: Does anybody know a simple way to show linenumbers in a JTextArea?
    ... you can build a Ruler object (that shows line number, ... stick together in a panel, this ruler and the JTextArea, add this panel ... 1- Maybe you'll need a bit of hack to make the jscrollpane works well ... 2- je row height can be retreived through the JTextArea font! ...
    (comp.lang.java.programmer)
  • Re: JScrollPane in GridBagLayout
    ... Each of them is in a JScrollPane. ... Now I'm using GridBagLayout and it doesn't work:(No matter what the ... GridBagConstraints con = new GridBagConstraints; ... I'm adding a panel constructed like that to BorderLayout.CENTER of ...
    (comp.lang.java.gui)
  • Re: PROBLEM
    ... Actully i m using panel as canves and i wont to add verticall scroll ... JScrollPane scrollPane = new JScrollPane; ...
    (comp.lang.java.gui)
  • Re: Problem in JScrollPane
    ... > I have created a panel and sets it layout as null, ... > this panel in JScrollPane, then both scroll bar is coming but its ... > public class TestFrame extends JFrame{ ...
    (comp.lang.java.gui)