Solved

Search form with a tiled image background and transparent components.

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
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.

726 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