• Post Reply Bookmark Topic Watch Topic
  • New Topic

SWING - Changing java cup to my gif  RSS feed

 
Carty Ellis
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works:

public void go() {
JFrame frame = new JFrame("DARS Data Loader");
JPanel panel = new JPanel();
panel.setBorder(new EtchedBorder(EtchedBorder.RAISED));
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

ImageIcon image = new ImageIcon("WizardTiny.GIF");
frame.setIconImage(image.getImage());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


This does not:

public class SwingSerial extends JDialog {

public SwingSerial(JFrame frame) {
super(frame, true);
setTitle( "DARS Serialize D/B" );
ImageIcon image = new ImageIcon("WizardTiny.GIF");
setIconImage(image.getImage());
setSize(500, 300);



The Title works, but I can't get the image to replace the cup. I anticipate my approach to be wrong, but what would be the "recommended" method?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ensure the logo has changed on the JFrame,
then pass the JFrame to the dialog

 
Carty Ellis
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I use this code:

public class SwingSerial extends JDialog {

public SwingSerial(JFrame frame) {

super(frame, true);
ImageIcon image = new ImageIcon("WizardTiny.GIF");
frame.setIconImage(image.getImage());
setTitle( "DARS Serialize D/B" );


The Title in the frame is changed, and the default (java cup) icon is gone. No errors are thrown. There is just no WizardTiny.GIF on the frame. If I comment out the ImageIcon line and the frame.setIconImage lines I get the java cup.

If I comment out just the ImageIcon line it wants an image defined.

If I comment out just the frame.setIconImage I get the java cup.

Where is the disconnect in what I am doing?

java 1.5.0_04
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say that you aren't loading the image correctly. Where is the image in relation to your class files?

ImageIcon image = new ImageIcon("WizardTiny.GIF");

And is your filename correct with caps and all?
 
Carty Ellis
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoops!

Was in wrong directory. Thanks. It works now.

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!