title: Resizing a JMenuItem?
body: <p>I'm currently trying to customise the size of my JMenuItems to make them larger. From this: </p>
  
  <p><a href="https://i.stack.imgur.com/dC90m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dC90m.png" alt="enter image description here"></a></p>
  
  <p>to more like this:</p>
  
  <p><a href="https://i.stack.imgur.com/4gu5i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4gu5i.png" alt="enter image description here"></a></p>
  
  <p>From the looks of things I've got a few options:</p>
  
  <p>1: To extend JMenuItem and override getPreferredSize(). Or I guess do this (which is how the above images were achieved):</p>
  
  <pre><code>    private JMenuItem getCustomMenuItem(String s){
      JMenuItem item = new JMenuItem(s){
          @Override
          public Dimension getPreferredSize(){
              return new Dimension(100, 20);
          }
      };
      return item;
  }
  </code></pre>
  
  <p><code>JMenuItem print = getCustomMenuItem("Print");</code></p>
  
  <p>But I'm pretty sure that this is frowned upon because the Layout manager might not respect the size I've given. I might also have to write or override other items, like JCheckBoxMenuItems.</p>
  
  <p>2: I could also add horizontal struts between each of the menu items to deal with vertical spacing, and use spaces on each side of the label to deal with the width of the menu. But this seems clunky, and likely to cause problems when I want to align text and images
  <code>menu.add(Box.createVerticalStrut(10))</code></p>
  
  <p>3: Or I could add a compound border to each menuItem:
  <code>menuItem.setBorder(BorderFactory.createCompoundBorder(menuItem.getBorder(), new EmptyBorder(5,5,5,5)))</code></p>
  
  <p>4: Or somehow tell the look and feel to set Menu item widths - which I don't really understand.</p>
  
  <p>Are there any other ways of doing this? Method 1 works, but I think adding a compound border is probably the way I should go. I suppose I could extend JMenuItem and add the border to the custom item (which would allow me to cast a JCheckBoxMenuItem too)? </p>
  
  <p>Any help is appreciated, haven't really been able to find a definitive answer on this and would like to know what the best practice is for customising components more generally whilst avoiding the whole get/set preferredSize() pitfalls.</p>