Solved

Search form with a tiled image background and transparent components.

Posted on 2001-08-20
5
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Expert Comment

by:hquoc
ID: 6408364
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
ID: 6408744
Sounds like your overriding paint() instead of paintComponent().
0
 
LVL 1

Author Comment

by:kllewelyn
ID: 6409886
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
ID: 6410110
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
ID: 6411559
> 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Glassfish admin console not working 1 87
restrict decimal places for double datatype 10 47
IBM TS2900 (3572) Tape Autoloader Java? 12 103
Java regex 5 20
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

737 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