• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to set an icon in the top right corner?

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A possible way of doing this:

 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Maneesh Godbole Thanks a lot! :-)
 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Carey Brown Would be pleased if you could help me here: https://coderanch.com/t/662742/GUI/java/Background-image-doesn-window#3079993
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Don't touch me. And dont' touch this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic