Swing
displaying an image in javax.swing
Date: 14 Mar 2003 18:28:23 -0800Newsgroups: comp.lang.java
Size: 1,536 bytes
Hi!
I am writting a program using netbeans ide. I am trying to display a
window with a picture, which I tried to put in the label. According to
everything I read it should work, however it doesn't display anything.
What is my mistake here? :-(
Thank you so much.
Here is the code:
public class Welcome extends javax.swing.JFrame { /** Creates new form Welcome */ public Welcome() { initComponents(); } /** This method is called from within the constructor to * initialize the form. */ private void initComponents() { logotip = new javax.swing.JLabel(); getContentPane().setLayout(new
org.netbeans.lib.awtextra.AbsoluteLayout()); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt)
{ exitForm(evt); } }); icon = new javax.swing.ImageIcon("twirlIcon.jpg"); logotip.setIcon(icon); logotip.getIcon(); getContentPane().add(logotip, new
org.netbeans.lib.awtextra.AbsoluteConstraints(100, 30, 200, 200)); pack(); } /** Exit the Application */ private void exitForm(java.awt.event.WindowEvent evt) { System.exit(0); } /** * @param args the command line arguments */ public static void main(String args[]) { new Welcome().show(); } // Variables declaration private javax.swing.JLabel logotip; private javax.swing.ImageIcon icon;
}
