Solved

Search form with a tiled image background and transparent components.

Posted on 2001-08-20
5
211 Views
Last Modified: 2010-05-18
I'm trying to make a search form with labels, text fields and combo boxes.  I also need the background component(not sure if it should be a panel, frame or what) to use an image and tile it. Not really sure where I should start or how/if this can be done... I made a panel that will tile an image, but it hides all components that I add to it. Like the painting of the image goes on top of the components.
0
Comment
Question by:kllewelyn
  • 2
  • 2
5 Comments
 

Expert Comment

by:hquoc
Comment Utility
Hi kllewelyn,
For ur quest, i see, u want to tile a background image on a container either Frame or Panel object. And then, u will lay a lables, textfields, combos on the container, ok.
I think u should use the swing object such as JPanel for container objects, and other are also swing objects.
And nextly, u may be, using snippet such below to load an background image:
//Create a panel object, after u will use it in ur main apps
class ImagePane extends JPanel {
        Image background;
   
        public ImagePane(Image background{
            this.background = background;
        }
        //Draw the current frame of image.
        public void paintComponent(Graphics g) {
            super.paintComponent(g);  //paint any space not covered
                                      //by the background image
            int compWidth = getWidth();
            int compHeight = getHeight();
            int imageWidth, imageHeight;
   
            //If u have a valid width and height for the
            //background image, draw it.
            imageWidth = background.getWidth(this);
            imageHeight = background.getHeight(this);
            if ((imageWidth > 0) && (imageHeight > 0)) {
                g.drawImage(background,
                            (compWidth - imageWidth)/2,
                            (compHeight - imageHeight)/2, this);
            }
        }
}

In the main program, u have to import the above class and then inserting following snippet:

Image bgImage = Toolkit.getDefaultToolkit().getImage("filename");
ImagePane p = new ImagePane(bgImage);
p.add(JLabel);//so on
Frame.add(p, BorderLayout.CENTER);


i hope it will help u,
regards,
huuquoc
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
Comment Utility
Sounds like your overriding paint() instead of paintComponent().
0
 
LVL 1

Author Comment

by:kllewelyn
Comment Utility
Is it bad to use swing components? I mean, what version of explorer can handle the swing components? I was using AWT because I heard they are supported by earlier versions.
0
 
LVL 1

Author Comment

by:kllewelyn
Comment Utility
Is it bad to use swing components? I mean, what version of explorer can handle the swing components? I was using AWT because I heard they are supported by earlier versions.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> what version of explorer can handle the swing components?

It's not dependant on the explorer version, it's related to your jre.
But Swing is supported by jre 1.1+.

Though it is not a standard part of the jre until 1.2.

To use Swing in an applet you'll generally need the plugin installed.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now