I am last year BSc(I.T) student. I am doing one live project. In that project I have to change JFrame image icon. I tried different techniques but not any of them worked out. Can anybody tell me how to change JFrame image icon? Thanks in advance.
I am last year BSc(I.T) student. I am doing one live project. In that project I have to change JFrame image icon. I tried different techniques but not any of them worked out. Can anybody tell me how to change JFrame image icon? Thanks in advance.
Using following program you will able to learn How to change JFrame image icon. In the following program I have use rame.setIconImage(Toolkit.getDefaultToolkit().get Image("test.jpg")); method to change JFrame image icon. You have to just add javax.swing.* class to do this.
Code:import javax.swing.*; import java.awt.*; public class SettingIconFrameEg { public static void main(String[] args){ JFrame frames = new JFrame("Set an image for a frame"); frame.setIconImage(Toolkit.getDefaultToolkit().getImage("test.jpg")); frames.setDefaultCloseOperation(JFrames.EXIT_ON_CLOSE); frames.setSize(400,250); frames.setVisible(true); } }
Last edited by TaylorRyan; 02-09-2010 at 04:15 PM.
Try to understand following code which given below. In the following code I use mageIcon loadImageIcon(String filenames) method to receive image from one folder and assigning to Jframe.
Code:public static ImageIcon loadImageIcon(String filenames) { URL urls = Configs.class.getClassLoaders().getResources( IMAGE_DIR + filenames); if (urls == null) { System.err.println("image does not exits" + filenames); return null; } ImageIcon icons = new ImageIcon(urls); return icons; }
Bookmarks