Results 1 to 10 of 10
  1. #1
    AWPtic is offline Member
    Join Date
    Mar 2009
    Posts
    39
    Rep Power
    0

    Default Images in JFrame

    Hi, I am having trouble with making images (.jpg) show up in a JFrame. I'm not wanting them to be a background, but instead just the picture itself show up. Can someone please help me?

  2. #2
    faisalcmpm is offline Member
    Join Date
    Feb 2009
    Posts
    22
    Rep Power
    0

    Default

    Just use a JLabel

  3. #3
    AWPtic is offline Member
    Join Date
    Mar 2009
    Posts
    39
    Rep Power
    0

    Default

    I am but what I mean is how do I import them so I can use them as a variable.

  4. #4
    AWPtic is offline Member
    Join Date
    Mar 2009
    Posts
    39
    Rep Power
    0

    Default

    Oh yeah, also I'm trying to make the picture a JButton. I'm having it where they can choose their character, so it needs to have the picture displayed and clickable.

  5. #5
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    12

    Default

    For images, you can just create your own JComponent, add it to the contentpane of the JFrame, and override the paintComponent method.

    Java Code:
    class MyClass extends JComponent {
      public void paintComponent(Graphics g) {
         super(g);
    
         g.drawImage(...the applicable parameters...);
      }
    }
    To have an image be the icon for a button, use ImageIcon.

  6. #6
    AWPtic is offline Member
    Join Date
    Mar 2009
    Posts
    39
    Rep Power
    0

    Default

    So, something like this would work?

    ImageIcon terminator = new JButton(KarateTerminator.jpg);

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

  8. #8
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    12

    Default

    No, but somethng like this would...

    Java Code:
    JButton terminator = new JButton(new ImageIcon("....jpg"));

  9. #9
    AWPtic is offline Member
    Join Date
    Mar 2009
    Posts
    39
    Rep Power
    0

    Default

    what class do I have to import for ImageIcon?

  10. #10
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    12

    Default

    Java Code:
    import javax.swing.*;

Similar Threads

  1. XML Images
    By JavaWizz in forum XML
    Replies: 1
    Last Post: 10-17-2008, 10:19 AM
  2. images
    By amith in forum AWT / Swing
    Replies: 3
    Last Post: 06-27-2008, 08:38 PM
  3. images
    By amith in forum AWT / Swing
    Replies: 1
    Last Post: 05-20-2008, 10:54 AM
  4. Help with images...
    By toby in forum Java Applets
    Replies: 1
    Last Post: 08-04-2007, 05:25 AM
  5. Images in JSP
    By Daniel in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-05-2007, 06:01 AM

Posting Permissions

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