how to add an icon in tne frame title using JAVA-Swing
843785Nov 14 2008 — edited Nov 14 2008HI,
I am new to java swing.In my application,I need to add an Icon (abc.gif) in the frame title but I am not able to do it.this icon is in my local system.
So Please help me to resolve this issue.
I am attaching the code here --
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.*;
public class demo {
JRadioButton R_button;
demo()
{
super();
/***************************** Crating a New Frame ********************************/
JFrame frame = new JFrame("Setup");
frame.setBounds(400, 200, 500, 500);
//frame.setForeground(Color.YELLOW);
/**********************************************************************************/
JButton button,button1;
JPanel panel,panel1,panel2;
JMenuBar mainMenuBar;
JMenu menu1, menu2, submenu;
JMenuItem item1,item2;
button = new JButton("Install");
button1 = new JButton("Cencle");
R_button = new JRadioButton("Install");
panel = new JPanel();
panel1 = new JPanel();
panel2 = new JPanel();
panel.setLayout(new FlowLayout());
panel1.setLayout(new FlowLayout());
panel.setBackground(Color.LIGHT_GRAY);
panel1.setBackground(Color.LIGHT_GRAY);
panel2.setLayout(new FlowLayout());
panel2.setBackground(Color.LIGHT_GRAY);
JToolBar MainToolbar = new JToolBar();
JLabel lable = new JLabel("Text Message");
// MenuBar menu = new MenuBar();
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
Nxt_frame frame2 = new Nxt_frame();
//System.exit(0);
}
});
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
//setVisible(true);
/**********************************************************************/
mainMenuBar = new JMenuBar();
menu1 = new JMenu("File");
menu2 = new JMenu("Edit");
mainMenuBar.add(menu1);
mainMenuBar.add(menu2);
item1 = new JMenuItem("New", KeyEvent.VK_N);
item2 = new JMenuItem("Open File", KeyEvent.VK_O);
frame.setJMenuBar(mainMenuBar);
/**********************************************************************/
//MenuBar menu = new MenuBar();
//panel.add(MainToolbar);
/* frame.add(panel);
panel.add(mainMenuBar);
panel.add(menu1);
panel.add(menu2);*/
menu1.add(item1);
menu1.add(item2);
panel.add(lable);
panel2.add(R_button);
panel1.add(button);
panel1.add(button1);
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.getContentPane().add(panel1, BorderLayout.SOUTH);
frame.getContentPane().add(panel2, BorderLayout.EAST);
//frame.setDefaultLookAndFeelDecorated(true);
//frame.setDefaultLookAndFeelDecorated(true);
frame.setIconImage(new ImageIcon().getImage());
frame.setIconImage(Toolkit.getDefaultToolkit().getImage("abc.gif"));
frame.setResizable(false);
frame.setVisible(true);
}
public static void main(String[] args) {
demo de = new demo();
}
}
thanks in Advance ......