Making a custom icon for a JFrame

Well I was wondering if I could make an icon image for a JFrame. I do know its posible, because, let me say, I am NOT digging the java logo.

Well if I just hava to use a Frame object I will.

Can someone tell me, I know its possible!


First, you have to have an image file on your computer. It can be named anything. For this example, we will call this one "pic.jpg". Next, you need to include it in the files that your application is using. For example, if you're using NetBeans, you simply click on "Files" in the left hand side of the IDE (not File as in the menu, mind you). Drag the picture's file over to the folder that houses the main package. This will include it for available use in the code. Inside the method where you define the JFrame, you can create an image like this:

Image frameImage = new ImageIcon("pic.jpg").getImage();

You can now set it as the IconImage for the frame like this:

JFrame frame = new JFrame("Title");

Hope that's helpful.

Note: the reason that the Image object has to be created like this is because Image is abstract and cannot be instantiated by saying new Image();

Props to you, btw, kid. I wish I would have started learning programming when I was your age. Keep at it!

Use an ImageIcon.

ImageIcon icon = new ImageIcon( pathToIcon );

Good Luck!

Need Your Help

jQuery: How to block checkboxes for checking when certain condition is met

jquery html checkbox count

I have a HTML form with a number of checkboxes that all have the same class = "shared".

invalid use of template-name without an argument list

c++ templates

So i have a class name repository which is just a simple array.Here is a part of the class:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.