Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

setting Icon Image in JDialog

843807Apr 12 2002 — edited Jun 21 2004
The 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);
}
}



Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 19 2004
Added on Apr 12 2002
3 comments
312 views