that statement is unbeleivably true.
right, heres my two classes, the first class is where i created the image
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.* ;
import java.io.*;
import javax.imageio.*;
public class EmailBackgroundImage extends JComponent
{
public void paint (Graphics g)
{
File bkgdimage = new File ("background.jpg");
Image imagebg = createImage ( 250,300 );
try {
imagebg = ImageIO.read(bkgdimage);
}
catch (IOException e)
{}
g.drawImage(imagebg, 0, 0,null,null);
}
}
/**************************************************************************/
this next class is where i'm trying to make the background
youll notice remnants of my current attempt to create the background image.
in its current state it does compile
/*********************************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.* ;
import java.sql.*;
import java.util.*;
import java.awt.color.*;
public class emailFrontpage extends JFrame implements ActionListener
{
JLabel FirstNameLabel= new JLabel("First Name");
JLabel LastNameLabel = new JLabel("Last Name");
JLabel EmailLabel= new JLabel("Email Address");
JTextField FirstNameText = new JTextField( 10 );
JTextField LastNameText = new JTextField( 10 );
JTextField EmailAddressText= new JTextField( 20 );
JPanel panel1= new JPanel();
JPanel panel2= new JPanel();
JPanel panel3= new JPanel();
JPanel panel4= new JPanel();
JPanel panel5= new JPanel();
JPanel image= new JPanel();
JButton Enterbutton = new JButton("Enter Details");
JButton Logon= new JButton("Log on");
EmailBackgroundImage myimage;
EmailEdit editEmp;
emailFrontpage()
{
getContentPane().setLayout( new BoxLayout( getContentPane(), BoxLayout.Y_AXIS ));
myimage = new EmailBackgroundImage();
image.add(myimage);
myimage.setSize(250,300);
image.setOpaque( false );
FirstNameLabel.setForeground(Color.WHITE);
LastNameLabel.setForeground(Color.WHITE);
EmailLabel.setForeground(Color.WHITE);
panel1.add(Logon);
panel2.add(FirstNameLabel); panel2.add(FirstNameText);
panel3.add(LastNameLabel); panel3.add(LastNameText);
panel4.add(EmailLabel);panel4.add(EmailAddressText);
panel5.add(Enterbutton);
getContentPane().add(image);
getContentPane().add(panel1);
getContentPane().add(panel2);
getContentPane().add(panel3);
getContentPane().add(panel4);
getContentPane().add(panel5);
// .setBackground( Color.black )
Enterbutton.addActionListener( this );
Logon.addActionListener( this );
Enterbutton.setActionCommand( "ENTERBUTTONPRESSED" );
Logon.setActionCommand( "LOGONBUTTONPRESSED" );
setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
editEmp = new EmailEdit();
}
public void actionPerformed( ActionEvent evt)
{
if ( evt.getActionCommand().equals("LOGONBUTTONPRESSED") )
{
emailLogonpage emaillogon = new emailLogonpage();
emaillogon.setSize( 250, 300 );
emaillogon.setVisible( true );
emaillogon.setResizable(false);
setVisible(false);
}
else
{
String newFN = FirstNameText.getText();
String newLN = LastNameText.getText();
String newEA = EmailAddressText.getText();
editEmp.addNewEmail(newFN, newLN, newEA);
setVisible(false);
emailFrontpage emailfront = new emailFrontpage();
emailfront.setSize( 250, 300 );
emailfront.setVisible( true );
emailfront.setResizable(false);
}
}
public static void main ( String[] args )
{
emailFrontpage emailfront = new emailFrontpage();
emailfront.setSize( 250, 300 );
emailfront.setVisible( true );
emailfront.setResizable(false);
}
}
> The trouble with subclassing like that is what if
> elsewhere you want a bakground image on your JTable's
> JViewport? On you JDesktopPane? Etc?
The op wanted a JPanel that has a background image. Hence the subclass solution. I didn't have a good look at the link you posted, but if it provides a better/more general solution, then I suggest the op to use that instead and award the good Dr with the dukes he deserves. =)
Cheers,
Jukka
First you post the question in the wrong forum. (Swing related questions should be posted in the Swing forum)
Then you start complaining every 10, 10, 5, minutes that no one is answering your question.
Well, if you even bothered to do a little searching of the forum you would have found your answer because this question is asked all the time.
Learn how to use the forum.