Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to set an icon in the top right corner?

 
Sophia Green
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have this window where I want to add a logout icon on the top right corner. And also I have tried adding a background image through many ways but it won't even appear.

I have tried adding the logout icon like this:

1st Method


2nd Method



None of them worked..


Here is my code:



Thanks for any help!
Screenshot (242).png
[Thumbnail for Screenshot (242).png]
This is where the logout icon us to be placed
Screenshot (241).png
[Thumbnail for Screenshot (241).png]
This is where the icon is being positioned when I tried
 
Carey Brown
Bartender
Posts: 2265
28
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A possible way of doing this:

 
Sophia Green
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Carey Brown Thanks a lot for your answer! Would be grateful to you if you could explain to me what you did 'cause I am new to Layouts :-)
 
Carey Brown
Bartender
Posts: 2265
28
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've become a fan of GridBagLayouts since using a drag-n-drop GUI design tool, though it is one of the more tedious to do by hand. I suggest looking up the constructor arguments to GridBagConstraints. As you may have notice I also needed to tweak how your panels were being added at the bottom of the program.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another possible way is to use MigLayout. My experience is that it is more easier to learn, and lesser parameters to configure. More on it here http://www.miglayout.com/

Here is my sample code and the UI it generates
1.jpg
[Thumbnail for 1.jpg]
 
Sophia Green
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Maneesh Godbole Thanks a lot! :-)
 
Sophia Green
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Maneesh Godbole I have already worked quite much on this till now so would stick to GridBagLayout but will try to use MigLayout next time. However, can you show me how I can get the footer center aligned through GridBagLayout and also how I can get the border to be fixed instead of it stretching as the window size increases?
 
Carey Brown
Bartender
Posts: 2265
28
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For trimming border to copyright, try

It would help to rename some of your variables, e.g. pnl2 would become copyrightPanel.
 
Sophia Green
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Carey Brown Thanks a lot, but that didn't change anything. I actually wanted the border to remain fixed and also the label to be centered in the border
 
Sophia Green
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Carey Brown Would be pleased if you could help me here: http://www.coderanch.com/t/662742/GUI/java/Background-image-doesn-window#3079993
 
Carey Brown
Bartender
Posts: 2265
28
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sophia Green wrote:@Carey Brown Thanks a lot, but that didn't change anything. I actually wanted the border to remain fixed and also the label to be centered in the border

If I understand you correctly, you want the copyright text to be centered near the bottom of the screen and you want a horizontal line to appear above the text that is the width of the text and doesn't stretch if the user resizes the frame. If that is what you want, then the change I gave you worked for me. Otherwise, my copy of your code may be out of sync with yours. Could you repost your code in its entirety?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!