Java Swing Element Transitions

I am trying to create a small non-profit application and make it a well-designed interface, with screens, etc. I have each "screen" on separate panels in one JFrame and you want them to slide them smoothly when switching between panels. Is there a way to make this somewhat easy?

+7
source share
4 answers

Since you have not yet accepted the answer, can I offer you the SlidingLayout library ? This is a very small library, the purpose of which is to create smooth transitions between the two layouts of some components. Thus, the transition between the two screens is very simple. Here is an example I just made:

enter image description hereenter image description here

The difference between the two transitions is based on two lines of code. You can also create more fancy transitions by applying a different delay for each component, so they do not appear all at the same time, but with some temporary changes between them.

I hope you find this helpful :)

+7
source

This is a typical example of using animation. The easiest way is to use an animation framework . I suggest Trident

+3
source

I wrote a simple Java program to perform simple slide transitions. You can adapt it to other things (rather than slipping).

Here is a link to my implementation: http://www.java-forums.org/entry.php?b=1141

And here is the listener that I wrote to detect a finger drag on the screen:

import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; /** * * @author Ozzy */ public class GestureListener implements MouseListener, MouseMotionListener { int dragStartX; int dragStartY; int dragEndX; int dragEndY; int currentX; int currentY; boolean dragged; private void dragGesture() { if (dragged) { int distance = dragEndX - dragStartX; System.out.println("Drag detected. Distance: " + distance); if (distance > 144) /** 2 inches on 72dpi */ { //finger going right MyApp.scrollLeft(); } else if (distance < -144) { //finger going left MyApp.scrollRight(); } else { //do nothing } dragged = false; } } public void mouseDragged(MouseEvent e) { dragged = true; Point pos = e.getPoint(); dragEndX = pos.x; dragEndY = pos.y; } public void mouseMoved(MouseEvent e) { Point pos = e.getPoint(); currentX = pos.x; currentY = pos.y; } public void mouseClicked(MouseEvent e) { } public void mousePressed(MouseEvent e) { Point pos = e.getPoint(); dragStartX = pos.x; dragStartY = pos.y; } public void mouseReleased(MouseEvent e) { dragGesture(); } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } } 

Hope this helps.

0
source

Alternatively, you can use this simple animated AnimaationClass library to move JComponents around its x and y axes, then hide / get rid of them. This provides decent (basic and smooth) animation.

http://www.teknikindustries.com/downloads.html

It comes with javadoc if you somehow do not understand.

0
source

All Articles