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 / December 2003

Tip: Looking for answers? Try searching our database.

Setting the background with an image Pattern

Thread view: 
willy - 30 Dec 2003 04:33 GMT
Hi,

I'm looking for a way to set the background pattern with an image (i.e.
loaded as a gif).

I'd like the background to be filled (and act as a pattern rather than a
background image) with a given gif, even after resizing.

Thanks for any tips.

WT-
ak - 30 Dec 2003 08:46 GMT
> Hi,
>
[quoted text clipped - 3 lines]
> I'd like the background to be filled (and act as a pattern rather than a
> background image) with a given gif, even after resizing.

something like this:

public class JPatternPanel extends JPanel {

   Image pattern;

   public void paintComponent(Graphics g) {
       super.paintComponent(g);
       Insets insets = getInsets();
       Dimension size = getSize();
       if(patterm != null) {
           int width = pattern.getWidth(null);
           int height = pattern.getHeight(null);
           if(width > 0 && height > 0) {
               for(int i = insets.left; i < size.width - (insets.left +
insets.right); i += width) {
                   for(int j = insets.top; i < size.height - (insets.top +
insets.bottom); j += height) {
                       g.drawImage(pattern, i, j, null);
                   }
           }
   }
   //paint here whatever you need
}

____________

http://reader.imagero.com the best java image reader.


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.