Results 1 to 6 of 6

Thread: Scroll a JPanel

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181

    Scroll a JPanel

    Hi

    Is there a way to make a JPanel scroll. I know it can be done using the JViewPort and JScrollbars, and implementing the JScrollable interface, but does anyone have anything like that already that i might be able to use. I guess i'm being lazy, but i'm also short on time.

    I need to be able to scroll a panel, because on that i'm creating shapes, that are dynamically made and added, thus if the height of the total shapes changes, then it goes off the panel.

    If the Jpanel is not scrollable, are there alternatives to this probelm?

    Any input is appreciated..Thanx in advance

    --770

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181
    I should really do some more research before posting and asking the question...

    you can just apply a JPanel to a JScrollPane... ...


    -770

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181
    back to this question...

    i'm trying to add labels to this Jpanel, but it won't seem to show them..

    (this is an applet)
    so in the init() if i do
    Code:
    JLabel lblTest;
    lblTest = new JLabel("TESTING");
    panel.add(stackObject);
    it works

    but if i do the same code in any other method the label doesn't show up on the panel. i've tried to do panel.repaint(), which does nothing

    this jpanel is connected to a jscrollpane (not sure if i have to do anything diff for the components to show up....i can add all the stuff i want in the init() method, but if i put the same code in a diff method, it doesn't work........ HELPPP

    --770

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Try to call panel.invalidate() or something like that before repaint.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181
    yes, i got it

    i used revalidate(); and it works fine

    but in other places i'm using repaint();...i tried replacing those places with revalidate(), but that doesn't work...

    very werid...not sure why that is....

    so it's a matter of trial and error of which one work for that particular code or component... which programming shouldn't be....lol

    --770

  6. #6
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Try setting the Layout Manager before u add any component to the panel..
    To add into the scrollpane..

    JScrollPane jp = new JScrollPane(myPanel);
    then add jp to the main container...

    and that should be enough...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width