• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
shariq khan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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]
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!