Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JDialog Icon

 
Yoo-Jin Lee
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This was at http://www.esus.com/javaindex/j2se/jdk1.2/javaxswing/toplevelcontainers/jdial og/jdialogicon.html.
You can set the top-left icon with the following:
<code>
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("first.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("second.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);
}
}
</code>
However, if you set the resizable to false then it does not work.
Any ideas?
Thanks.
Yoo-Jin
[This message has been edited by Yoo-Jin Lee (edited November 16, 2001).]
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Yoo, the code is working very fine with me when i m using setResizable(false); for any or both of JFrame and JDialog. Possibly some other problem in ur code. You can try the following modified code :
[B][/B]
------------------
Muhammad Ashikuzzaman (Fahim)
Sun Certified Programmer for the Java� 2 Platform
--When you learn something, learn it by heart!
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!