Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

view before and after Tsunami

 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Can any java function let user drag left and right to view before and after Tusnami?
Please navigate to the following web site.
http://www.cnn.com/interactive/2011/03/world/slider.japan.photos/index.html?hpt=T2
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All you need to do is to change the crop of the overlay image.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:All you need to do is to change the crop of the overlay image.


I would like to lean and understand everything about Java, and I am wondering.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12127
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think what Bear is saying is that you display one picture right on top of the other. then, one you change where the top one is cropped based on the mouse movement.
 
Rob Spoor
Sheriff
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tweaking JSplitPane could help you out. It will try to place the contents of both the left and right hand sides at the top left of its panes, but using either custom painting or a custom layout could help you out.

What may work (haven't tried it):
- create a JPanel with a FlowLayout set to have FlowLayout.LEFT as its alignment. Add a JLabel with the before image to it.
- create a JPanel with a FlowLayout set to have FlowLayout.RIGHT as its alignment. Add a JLabel with the after image to it.
- create a JSplitPane with those two panels
- tweak the JSplitPane (e.g. the divider size, divider location, etc) to get a better look
 
Rob Spoor
Sheriff
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, and now I've tested it a bit. Quick and dirty:
The minimum sizes are required to allow one panel to be completely hidden by the divider. The setting of the preferred size of the JSplitPane is to prevent the left and right panels to both be shown initially (although this will still occur if the JSplitPane is resized).

Just one note: the setDividerLocation(0.5) doesn't work yet because if "the split pane is not correctly realized and on screen, this method will have no effect" (quoted from the Javadoc page of JSplitPane). Setting it to an int value based on the new preferred size should work though.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15288
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your could do that with Swing GUI components, such as JSplitPane as Rob showed, or by drawing the images yourself with the 2D graphics API.

You can find good tutorials here:

Creating a GUI With JFC/Swing
2D Graphics
 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for the program. I very appreciate you posting the program.



Rob Spoor wrote:Right, and now I've tested it a bit. Quick and dirty:
The minimum sizes are required to allow one panel to be completely hidden by the divider. The setting of the preferred size of the JSplitPane is to prevent the left and right panels to both be shown initially (although this will still occur if the JSplitPane is resized).

Just one note: the setDividerLocation(0.5) doesn't work yet because if "the split pane is not correctly realized and on screen, this method will have no effect" (quoted from the Javadoc page of JSplitPane). Setting it to an int value based on the new preferred size should work though.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:Your could do that with Swing GUI components, such as JSplitPane as Rob showed, or by drawing the images yourself with the 2D graphics API.

You can find good tutorials here:

Creating a GUI With JFC/Swing
2D Graphics


Thank you for the tip.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic