File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes background image on JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "background image on JPanel" Watch "background image on JPanel" New topic
Author

background image on JPanel

Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
I looked at the code in the FAQ and tried to implement it, but I figure I'm missing an import. I am receiving the following error when I try to compile:

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Take a look at the java.awt.* package.


GenRocket - Experts at Building Test Data
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Ok, that got the image there, thanks. The only problem is that the image is tiny and misplaced. I was expecting it to take up the entire background.



Here is a snipet of the code:


pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Mike Lipay wrote:Ok, that got the image there, thanks. The only problem is that the image is tiny and misplaced. I was expecting it to take up the entire background.


You need to make it do this by either making your BackgroundPanel object become the contentPane or adding it to the contentPane BorderLayout.CENTER. You seem to be doing this with the pnl variable not the bp variable. Get rid of pnl and use bp instead, and I'll bet your problems are solved.

Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Thanks, I had figured that out, but got involved with another problem. Perhaps someone could help. I am trying to pass the size of the image back to the class that builds the panel. I am using an array to pass the width and height, but I can't seem to get it to work:



The compile error I am getting is:

AutoHistory.java:17: cannot return a value from method whose result type is void
return size;
^

I've set the sizes before doing the return, what's the problem?
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Never mind, got it working 99%, the only issue I need to work out is that the fields I am adding to the panel have a gray background instead of the image (ex: rounded buttons have a square border around them that is gray). I need to figure out how to make the borders transparent.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Mike Lipay wrote:Never mind, got it working 99%, the only issue I need to work out is that the fields I am adding to the panel have a gray background instead of the image (ex: rounded buttons have a square border around them that is gray). I need to figure out how to make the borders transparent.


button.setOpaque(false)
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Thanks, that did it!

I do have a question about combo boxes, why is it that the first item isn't automatically selected, or selectable? I've noticed that if I have three items in a combo box that I have to select item two or three, then go back and select item one in order for item one to be registered as being selected? This has cause me to create a dummy first entry called "Select Vehicle".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: background image on JPanel