Netbeans GUI builder trying to create Image Background on JDialog
In using the Netbeans 5.5 GUI builder (to build a JDialog box with 2 labels, 2 text fields, and a button) code has been pre-generated as follows:
// some imports
publicclass logonextends JDialog
{
/** Creates new form logon */
public logon(Frame parent,boolean modal)
{
super(parent, modal);
initComponents();
}
privatevoid initComponents()
{
logonPanel =new javax.swing.JPanel();
userNameTextField =new javax.swing.JTextField();
passwordTextField =new javax.swing.JTextField();
userNameLabel =new javax.swing.JLabel();
passwordLabel =new javax.swing.JLabel();
logonButton =new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("MyTitle");
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
logonPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
userNameLabel.setText("User name:");
passwordLabel.setText("Password:");
logonButton.setText("Logon");
// more code to add above items to panel
pack();
}
publicstaticvoid main(String args[])
{
java.awt.EventQueue.invokeLater(new Runnable()
{
publicvoid run()
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (InstantiationException ex)
{
ex.printStackTrace();
}
catch (UnsupportedLookAndFeelException ex)
{
ex.printStackTrace();
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
catch (IllegalAccessException ex)
{
ex.printStackTrace();
}
finally
{
new logon(new javax.swing.JFrame(),true).setVisible(true);
}
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton logonButton;
private javax.swing.JPanel logonPanel;
private javax.swing.JLabel passwordLabel;
private javax.swing.JTextField passwordTextField;
private javax.swing.JLabel userNameLabel;
private javax.swing.JTextField userNameTextField;
// End of variables declaration
}
The GUI builder seems to create this logon class as a Runnable. I am now wanting to insert an image as the background for the JDialog box. I have looked at numerous topics on this subject. All seem to state the need to override the paintComponents method.
However, adding the logic:
// override paintComponents method
publicvoid paintComponents(Graphics g)
{
// get image
ImageIcon icon =new ImageIcon("c:/logon_background.jpeg");
// Dispaly image at at full size
g.drawImage(icon.getImage(), 0, 0,null);
if( isOpaque() ){ super.paintComponents( g );}
}
to the class logon seems to add no value - and running the debugger proves this overriden method never gets used. Can anyone tell me what I am missing?
Thank you!

