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 08-07-2007, 03:01 AM
Member
 
Join Date: Jul 2007
Posts: 40
barney is on a distinguished road
How can we zoom a map using JSlider
Hi, how can we zoom a map using JSlider in swings.
If anybody having code please send to me.

Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-07-2007, 08:18 AM
zoe zoe is offline
Member
 
Join Date: Jul 2007
Posts: 40
zoe is on a distinguished road
Image Pan Applet by Masswire Inc.

check out this link, then click the download button. This should help.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-07-2007, 10:25 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
Code:
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_INTERPOLATION, 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/world_map.gif"; 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
  #4 (permalink)  
Old 01-04-2008, 09:49 AM
tuffturn29's Avatar
Member
 
Join Date: Jan 2008
Posts: 1
tuffturn29 is on a distinguished road
how can i provide volume control using JSlider???can anyone provide me some solution??
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
java: zoom type feature?? newtojava7 Advanced Java 1 04-02-2008 06:15 PM
Help with zoom in java cachi Enterprise JavaBeans 1 08-07-2007 08:55 AM
How To:Use a JSlider to adjust Text size in a JPanel louiebagz AWT / Swing 2 07-01-2007 08:37 AM
zoom in swing Alan AWT / Swing 2 05-31-2007 03:11 PM


All times are GMT +3. The time now is 03:36 AM.


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