Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-05-2008, 06:22 PM
Member
 
Join Date: May 2008
Posts: 11
Panchitopro is on a distinguished road
Scale 2 or more pictures using a JSlider
Hi everybody,

This is my first message, I try to learn Java.

I would like to know how I can display 2 or more images and then make scale in these images on the same time.

Thank you.

Francisco

I found this code here in Java Forums this is my reference:

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Hashtable;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.*;

public class MapScale extends JPanel {
BufferedImage image;
double scale = 1.0;

public MapScale(BufferedImage image) {
this.image = image;
}

protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATI ON,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
double x = (getWidth() - scale*image.getWidth())/2;
double y = (getHeight() - scale*image.getHeight())/2;
AffineTransform at = AffineTransform.getTranslateInstance(x,y);
at.scale(scale, scale);
g2.drawRenderedImage(image, at);
}

public Dimension getPreferredSize() {
int w = (int)(scale*image.getWidth());
int h = (int)(scale*image.getHeight());
return new Dimension(w, h);
}

private JSlider getSlider() {
int min = 1, max = 36, inc = 5;
final JSlider slider = new JSlider(min, max, 16);
slider.setMajorTickSpacing(5);
slider.setMinorTickSpacing(1);
slider.setPaintTicks(true);
slider.setSnapToTicks(true);
slider.setLabelTable(getLabelTable(min, max, inc));
slider.setPaintLabels(true);
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int value = slider.getValue();
scale = (value+4)/20.0;
revalidate();
repaint();
}
});
return slider;
}

private Hashtable getLabelTable(int min, int max, int inc) {
Hashtable<Integer,JLabel> table = new Hashtable<Integer,JLabel>();
for(int j = min; j <= max; j += inc) {
String s = String.format("%.2f", (j+4)/20.0);
table.put(Integer.valueOf(j), new JLabel(s));
}
return table;
}

public static void main(String[] args) throws IOException {
String path = "images/GIRL.JPG";
BufferedImage image = ImageIO.read(new File(path));
MapScale test = new MapScale(image);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new JScrollPane(test));
f.getContentPane().add(test.getSlider(), "Last");
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Funny Pictures Thread(this means a lot of pictures...) joshua Jokes and Funny Things 8 05-08-2008 07:36 AM
Small scale Java Editor Greenfrog99 AWT / Swing 0 01-27-2008 09:46 PM
How can we zoom a map using JSlider barney AWT / Swing 3 01-04-2008 09:49 AM
Help with pictures en Java susan AWT / Swing 1 08-07-2007 05:36 AM
How To:Use a JSlider to adjust Text size in a JPanel louiebagz AWT / Swing 2 07-01-2007 08:37 AM


All times are GMT +3. The time now is 11:41 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org