Search code examples
javajscrollpanegraphics2d

Using JScrollpane with the drawline() method


If the drawline() method does not add components, how can I display lines hidden off the side of the page with a JScrollpane?


Solution

  • JScrollPane use the component's getPreferredSize result to make determinations about how large the component is and if it needs to show the scroll bars or not.

    Start by overriding the component's getPreferredSize method and return an appropriate size which meets the component's current needs

    I would recommend having a look at How to use scroll panes for more details