Results 1 to 9 of 9
  1. #1
    Neomus is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Question Help with getWidth andgetHeight please.

    could someone explain to me how getWidth and getHeight work? Im having zero luck with finding a guide for it. I need to know the "formula" for it and maybe an example too. Thanks for any help :)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,386
    Rep Power
    25

    Default

    Are those methods your talking about? What class are they defined in? Sun's API doc will tell you how to use them and what they return when called.

    What is the "forumla" that you mention?

  3. #3
    Neomus is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default

    they are methods. Im not etirely sure what class they are supposed to be defined in a class I created but im notsure how touse them, and forget i mentioneda formula... i just ment that i wanted a generic explanation.

  4. #4
    Neomus is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default

    what i am tryingto do is figure out the width and height ofa picture so i can change the borders of the picture.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,386
    Rep Power
    25

    Default

    Where is the picture? In a disk file like a .jpg? Have you read it into an Image object?
    How are you accessing the borders to be able to change them?
    Are you writing a class with the get methods? If you don't know what height and width mean, I don't know what to say. That's a pretty basic concept when describing rectangular shapes.

  6. #6
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    what i am tryingto do is figure out the width and height ofa picture so i can change the borders of the picture.
    The abstract Image class has getWidth and getHeight methods that have a single parameter (which can be null).
    The BufferedImage class has getWidth and getHeight methods.
    If your image is mounted in a JLabel you can use the JLabel method getIcon and with it use the Icon methods getIconWidth and getIconHeight.
    Java Code:
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.URL;
    import javax.swing.*;
    
    public class WidthAndHeight {
        public static void main(String[] args) throws IOException {
            String path = "http://www.java-forums.org/images/ca_evo/misc/logo.gif";
            URL url = new URL(path);
            BufferedImage image = javax.imageio.ImageIO.read(url);
            int width = image.getWidth();
            int height = image.getHeight();
            System.out.printf("width = %d  height = %d%n", width, height);
            JOptionPane.showMessageDialog(null, new ImageIcon(image), "logo",
                                          JOptionPane.PLAIN_MESSAGE);
        }
    }

  7. #7
    Neomus is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default

    thanks forthe help hardwired. And thanks for trying norm :)
    Last edited by Neomus; 11-05-2008 at 11:20 PM.

  8. #8
    waqas.ramzan is offline Member
    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

    Default

    i want to change the icon of JOptionpane........Plz help me

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Img.getWidth(null); gives -1 why?
    By willemjav in forum New To Java
    Replies: 0
    Last Post: 02-15-2008, 02:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •