Results 1 to 3 of 3
Thread: JFrame + image
- 05-07-2009, 05:54 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 13
- Rep Power
- 0
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); } }
- 05-07-2009, 06:18 AM #2
Image.getScaledInstance()
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-07-2009, 06:34 AM #3
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
-
Add an image to JFrame
By Eranga in forum AWT / SwingReplies: 4Last Post: 02-01-2010, 04:09 PM -
can display image in JFrame?
By xCLARAx in forum AWT / SwingReplies: 14Last Post: 04-03-2009, 08:02 PM -
Need Help!!! Loading Image Into A Jframe
By lolshooter in forum New To JavaReplies: 3Last Post: 01-06-2009, 08:14 AM -
Image size in a JFrame
By nickbeacroft in forum AWT / SwingReplies: 2Last Post: 06-26-2008, 05:08 PM -
GUI... setting my background to an image, im using a JFrame
By newtojava7 in forum New To JavaReplies: 2Last Post: 03-24-2008, 06:29 AM
Bookmarks