Bookmark Topic Watch Topic
  • New Topic

Layout of window distorted after adding a background image  RSS feed

 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have a window where I added a background image which initially covered all the components of the frame. Then I called GridBagLayout which made the components reappear but the layout of the window changed ie they became messy.

Here is what I did to addthe background image:



Then in the end, I added:




Here is the full code:



Main



I want it to maintain its original layout with the background image. It's okay if the issue with the border at the bottom with its copyright label doesn't get fixed (in case it's too hard to do so) but would really like the logout icon to be in the upper right corner.
Thanks :-)
Screenshot-(246).png
[Thumbnail for Screenshot-(246).png]
This is how it looked before adding the background image
Screenshot-(248).png
[Thumbnail for Screenshot-(248).png]
Here is how it looks with the current codes
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Report post to moderator
That would fit better in our GUIs forum. Moving.
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Report post to moderator


I believe you need to set the layout BEFORE you add the panels to the frame, otherwise I don't think the constraints are saved by the layout manager, since by default a JLabel (which is now your content pane) uses a null layout until you specifically set the layout.
 
Les Morgan
Rancher
Posts: 767
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Sophia,

You can render an image onto the graphics context of another object like this:

It should not distort your layout as you are not adding any components, just painting the background of the object with an image.
 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Report post to moderator
@Rob Camick Thanks a lot!:-) That returned the layout back to how it should be and hence solved my question

@Les Morgan Thanks a lot for your answer
 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Report post to moderator
@Rob Camick Facing a similar problem for the user interface of a form. Can you please have a look at this: http://www.coderanch.com/t/662742/GUI/java/Background-image-doesn-window#3079993
 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Report post to moderator
@Les Morgan I tried your code but I am not able to make it work in this form..Can you please have a look here: http://www.coderanch.com/t/662742/GUI/java/Background-image-doesn-window#3079993
 
Les Morgan
Rancher
Posts: 767
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Report post to moderator
Sophia,

You have two threads running on the same code, and basically the same question, take a look in the other thread things are answered there for you.

Sophia Green wrote:@Les Morgan I tried your code but I am not able to make it work in this form..Can you please have a look here: http://www.coderanch.com/t/662742/GUI/java/Background-image-doesn-window#3079993
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks all for posting on this thread, but as you observe it's now redundant. I'm going to close this one and leave the other one for future answers.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!