Re: JScrollPane content sizing



On 2008-05-23 13:17 +0100, John allegedly wrote:
The Scrollable interface is what you are looking for. If you override the "getScrollableTracksViewportWidth()" method for your JPanel, and make it return true. The consequence is that the JPanel will have the size of the JViewport width.

That is indeed the answer the OP needed, AFAICT.


I have a question myself, which is related to the thread:

I have a JList in a JViewport, in a JScrollPane.

I want the opposite: the JScrollPane width should be the preferred width of the JList, but i don't manage to do it. The JViewport has the preferred size of the JList, but it's actual wdith is smaller.

Then set the minimum size.

You may set this up dynamically by subclassing the JViewPort's
getPreferredSize() and getMinimumSize() (and maybe getMaximumSize()) and
modifying the returned java.awt.Dimension Object to have its width field
match the desired value.
This might not be the most elegant solution, but it should work and has
the advantage being appliable to all (proper) LayoutManagers.


PS: please do not top-post.

--
DF.
to reply privately, change the top-level domain
in the FROM address from "invalid" to "net"
.



Relevant Pages

  • Re: JScrollPane content sizing
    ... If you override the "getScrollableTracksViewportWidth" method for your JPanel, ... The consequence is that the JPanel will have the size of the JViewport width. ... the JScrollPane width should be the preferred width of the JList, but i don't manage to do it. ...
    (comp.lang.java.gui)
  • Re: How to make disappear a JScrollPane vertical bar
    ... JViewport ... JPanel ... JScrollPane (=scrollSouth, BorderLayout.SOUTH) ...
    (comp.lang.java.gui)
  • How to make disappear a JScrollPane vertical bar
    ... JPanel ... JViewport ... JScrollPane ... I would like to make the sizes "fit" = make the top JScrollPane's vertical bar disappear. ...
    (comp.lang.java.gui)
  • Using JViewport with JPanel
    ... with a JPanel. ... I want to use the JViewport instead ... to manipulate the scrolling manually. ... public class TestImageMenu extends JFrame { ...
    (comp.lang.java.gui)
  • =?iso-8859-1?q?Re:_JPanel_l=E4uft_=FCber_JScrollPane_-_kein_scrollen?=
    ... public class Fehler extends JFrame implements ActionListener, ... private JPanel jp_Rechts2 = new JPanel; ... private JScrollPane jscrollpaneL = new JScrollPane; ... Next by Date: ...
    (de.comp.lang.java)