I\'m trying to display a high-width image in Java Swing (say 2000x100, like a heart rate strip). I need to show only a window of 500 width while it is slightly moving toward
The end of image should be concatenated with the beginning of the image. So it always repeats showing
Check out the Marquee Panel. You can add a JLabel
with an ImageIcon
to the MarqueePanel
.
The MarqueePanel
provides various method to customize the scrolling.
Edit:
The basic code would be:
MarqueePanel panel = new MarqueePanel();
panel.setWrap(true);
panel.setWrapAmount(0);
panel.setPreferredWidth(250);
JLabel label = new JLabel( new ImageIcon( "heartbeat.jpg" ) );
panel.add( label );
frame.add( panel );
If you want the image to fully appear at the left when it is displayed you can change the startScrolling()
method and use scrollOffset = 0;
.