aspose file tools*
The moose likes Java in General and the fly likes view before and after Tsunami Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "view before and after Tsunami" Watch "view before and after Tsunami" New topic
Author

view before and after Tsunami

Kee Kee moon
Ranch Hand

Joined: Dec 11, 2009
Posts: 147

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

Joined: Jan 10, 2002
Posts: 61240
    
  66

All you need to do is to change the crop of the overlay image.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kee Kee moon
Ranch Hand

Joined: Dec 11, 2009
Posts: 147
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

Joined: Oct 02, 2003
Posts: 11328
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

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

Joined: Aug 16, 2005
Posts: 14164
    
  19

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

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Kee Kee moon
Ranch Hand

Joined: Dec 11, 2009
Posts: 147
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

Joined: Dec 11, 2009
Posts: 147
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: view before and after Tsunami