• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

background image on JPanel

 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the java.awt.* package.
 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic