Solved

Search form with a tiled image background and transparent components.

Posted on 2001-08-20
5
214 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
configure dependency in POM for new database 3 34
throw exception 21 58
How to convert from xls to xlsx using java 7 55
Adding multiple JVM environments to RedHat 6 7 49
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

830 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