setting Icon Image in JDialog
843807Apr 12 2002 — edited Jun 21 2004The following code sets the top-left icon of a JDialog box.But when I uncomment the line
'setResizable(false)' the Icon is not seen.
So how do run the code if I want the JDialog box not Resizable ?
Code is as follows...................................
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
private AboutBox about;
public Main() {
super("Main test");
setSize(450, 350);
ImageIcon icon = new ImageIcon("no.gif");
setIconImage(icon.getImage());
JButton button = new JButton("Open dialog");
getContentPane().setLayout(new FlowLayout());
getContentPane().add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
about = new AboutBox(new JFrame());
about.setVisible(true);
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
}
public static void main(String []args) {
Main main = new Main();
main.setVisible(true);
}
}
class AboutBox extends JDialog {
public AboutBox(JFrame owner) {
super(owner, "About Swing Menu", true);
ImageIcon icon = new ImageIcon("no1.gif");
owner.setIconImage(icon.getImage());
JButton button = new JButton("Close");
getContentPane().setLayout(new FlowLayout());
getContentPane().add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
dispose();
}
});
setSize(250, 150);
// setModal(true);
// setResizable(false);
}
}