I'm creating desktop wallpaper for JFrame window. I've created and
added JLabel component with icon as a jpg file. but as i resize the
window it shows only it partially. I want the size of image on label to
be in size with label .
if there is any other better method then always appreciated.
import javax.swing.*;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
/**
* @author Bart Cremers
* @since Feb 23, 2006
*/
public class JImageFrame extends JFrame {
public JImageFrame(Image image) {
setContentPane(new ImagePanel(image));
}
public static void main(String[] args) throws IOException {
String pic = "somePic.jpg";
BufferedImage img = ImageIO.read(new File(pic));
JFrame f = new JImageFrame(img);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
f.setVisible(true);
}
private class ImagePanel extends JPanel {
private Image image;
public ImagePanel(Image image) {
this.image = image;
}
protected void paintComponent(Graphics g) {
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
}
}
Manoj Jain - 24 Feb 2006 07:48 GMT
oh ! thanks for the reply.
but i've already added JDesktopPane object in JFrame object.
will it work?
Bart Cremers - 24 Feb 2006 10:19 GMT
Should be more or less the same. Extend the JDesktopPane and override
the paintComponent in that one.
Bart
Manoj Jain - 25 Feb 2006 03:35 GMT
Sir,
In the application, I'm using JOptionPane.showMessageDialog(...) to
display the exceptions. I'm using SwingUItilities.invokeLater method to
display the MessageDilog box(above). Is it perofrmance-wise good ? I
then implemented Timer to shchedule database connectivity. but some
time later it shows SQLExceptions. So how the code should be?
I'm doing common activities through Timer like database connectivity,
Tree manipulation etc etc. Is it bug free?
You are the master, so if you have other architecture then plz
elaborate that one.
My application is not a big project. It is just a creating User,
Modules(for access to diff users) and Role. I'm using SWING to work out
these activities for Administrator.
so any suggestions are welcome.