Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Search form with a tiled image background and transparent components.

Posted on 2001-08-20
5
Medium Priority
?
219 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 800 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

609 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