Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sliding a jPanel

843806Jun 16 2008 — edited Jun 16 2008
Hi everyone.

I'm trying to create a sliding effect for a jPanel. The idea is that the user clicks a button and it scrolls left or right within another jPanel , as if it's rotating.

The actual moving part is easy, however I want it to actually slide rather than just move.

I have tried sleeping the thread for 10ms, moving the JPanel left one pixel, then repainting the panel - looped 70 times. however it seems that it doesn't physically move the jPanel until the loop has finished.

Here's the code I have:
    @Action
    public void SlideLeft() {
        if(jPanel1.getLocation().getX() < 0){
            for(double i = 1; i <= 70.0; i++){
                scroll(jPanel1, 1);
                try{
                    Thread.sleep(10);
                }catch(Exception e){
                    System.out.println(e.getMessage());
                }
            }
        }
    }
    public void scroll(javax.swing.JPanel what, int amount){
        Point temp = what.getLocation();
        temp.setLocation(temp.getX() + amount, temp.getY());
        what.setLocation(temp);
        jPanel2.repaint();
    }
jPanel1 is the panel I want to move within jPanel2 (which hides the contents of jPanel1 which aren't in the bounds of jPanel2).

How can I create a sliding effect for this?
(I'm quite new to Java, but not to programming in general).
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 14 2008
Added on Jun 16 2008
3 comments
1,627 views