Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2006

Tip: Looking for answers? Try searching our database.

How to make Image size as the label has?

Thread view: 
Manoj Jain - 23 Feb 2006 07:01 GMT
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.
Bart Cremers - 23 Feb 2006 08:20 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.