• 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

Java Swing JMenu's icon is not placed properly inside the menu

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I add only an icon to my JMenu.

If I use setPreferredSize(size of the icon) on JMenu, my icon is shifted to right in the JMenu.

If I use setSize(size of the icon) on JMenu, my icon is placed in center in the JMenu but has gaps on both sides.

Is there a way to align my icon properly or to expand so that its fills the menu space?

I can share my code snippets if required. Pic is attached.

Thanks
imageshift.png
[Thumbnail for imageshift.png]
imageshift2.png
[Thumbnail for imageshift2.png]
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please show us the code for that button and the icon.
 
shariq khan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My menu class:


My Applet:



My UI Class:


I replaced setPreferredSize with setSize which led to gap on both sides instead of only on left.

I am sorry if I missed some declaration, tried to provide a minimal implementation for one of the menus. Let me know if need any specific information which could help in figuring out the problem.

Thanks for the reply
 
reply
    Bookmark Topic Watch Topic
  • New Topic