JMenuItem Lead Space Removal

This will be a simple one I think…Does anyone know how to remove the leading space in front of the text in a JMenuItem? I’ve tried setHorizontalTextPosition(SwingContstants.LEFT); but it doesn’t do anything. I’m guessing the leading space is there for an icon, but I don’t want one there, and I don’t want the lead space either.

Basically, I’m trying to add a JMenuItem to the JMenuBar itself on occassion (as a link, rather than a menu).

I think the space is there for checkboxes and radio button indicators… Adding an icon shifts the text over so the icon lines up with the start of text for items that don’t have an icon.

There was a guy that did some l&f work and has guidelines for fixing this stuff in swing. Try looking on javadesktop.org

Ah here is what I was looking for:
http://www.jgoodies.com/freeware/metamorphosis/index.html

One more question for you…how do you get antialiased fonts in the menu? I tried overriding the paintComponent and adding renderinghints, but then when the menuitem is highlighted it looks really terrible. Any ideas?

These menus are really ruining the look of my application I think.

Let’s see the code you used for paintComponent. Maybe it can be fixed up to work good for highlighted items as well.

       public void paintComponent(Graphics g) {
              Graphics2D g2 = (Graphics2D) g;
              g2.addRenderingHints(
                          new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,
                                      RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
              g2.setColor(fontcolor);
              super.paintComponent(g2);
        }

Basically, I add the rendering hints and then send it on to super.

Well, I just tried completely rewritting the paintComponent without using super…and guess what? It still does it. :stuck_out_tongue:

Looks like my problem is that I’m using a dark highlight color with white text. If I use dark text and light highlight colors it’s not a problem. Ugh.

Anyone have a way of doing light text on dark backgrounds without the background seeping into the text?

You could try overriding getComponent() and return a JLabel set up to paint just how you want it.