Results 1 to 3 of 3

Thread: JFrame + image

  1. #1
    Blacknight is offline Member
    Join Date
    Feb 2009
    Posts
    13
    Rep Power
    0

    Default JFrame + image

    I'm trying to make a JFrame and just insert an image.
    Currently, it creates the JFrame, and then instead of setting the size of the image file, it resizes the JFrame because of "frame.setSize(100, 100);"(Not sure how to set the size of the Image instead)

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.Image;
    import java.awt.Toolkit;
    
    public class Test extends JFrame
    {
    	public static void main(String[] args)
    	{
    		Test frame = new Test(500 , 400);
    			Image im = Toolkit.getDefaultToolkit().getImage("images/Square.bmp");
    			frame.setIconImage(im);
    			frame.setSize(100, 100);
    			frame.setLocation(200, 200);
    			frame.setVisible(true);
    	}
    		public Test(int width , int height)
    		{
    			super("Test");
    			setSize(width , height);
    			setResizable(false);
    			setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    			FlowLayout flow = new FlowLayout();
    			setLayout(flow);
    			this.getContentPane().setBackground(Color.BLACK);
    			setVisible(true);
    		}	
    }
    Thanks

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Image.getScaledInstance()
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    I think you need to read the API for JFrame#setIconImage(...).

    Hint: It doesn't 'insert an image' to display on the JFrame.

    You may benefit from this tutorial:
    Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI with JFC/Swing)

    db

Similar Threads

  1. Add an image to JFrame
    By Eranga in forum AWT / Swing
    Replies: 4
    Last Post: 02-01-2010, 04:09 PM
  2. can display image in JFrame?
    By xCLARAx in forum AWT / Swing
    Replies: 14
    Last Post: 04-03-2009, 08:02 PM
  3. Need Help!!! Loading Image Into A Jframe
    By lolshooter in forum New To Java
    Replies: 3
    Last Post: 01-06-2009, 08:14 AM
  4. Image size in a JFrame
    By nickbeacroft in forum AWT / Swing
    Replies: 2
    Last Post: 06-26-2008, 05:08 PM
  5. Replies: 2
    Last Post: 03-24-2008, 06:29 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
  •