title: JTextField in JToolbar - cannot display properly in both Linux and Windows
body: <p>Please see the SSCCE below:</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Component;
  import java.awt.Dimension;
  import java.awt.EventQueue;
  
  import javax.swing.Box;
  import javax.swing.JComponent;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JTextField;
  import javax.swing.JToolBar;
  import javax.swing.UIManager;
  import javax.swing.border.EtchedBorder;
  
  
  @SuppressWarnings("serial")
  public class GlueTest extends JComponent {
  
      private JFrame frame;
      private JToolBar toolbar;
      private JLabel label_1;
      private JTextField textField_1;
      private JLabel label_2;
      private JTextField textField_2;
  
      public static void main(String[] args) {
          try {
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          } catch (Throwable e) {
              e.printStackTrace();
          }
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                  try {
                      GlueTest window = new GlueTest();
                      window.frame.setVisible(true);
                      window.frame.requestFocusInWindow();
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
      }
  
      public GlueTest() {
          initialize();
      }
  
      private void initialize() {
          frame = new JFrame("Test");
          frame.setBounds(0,0,800,600);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          toolbar = new JToolBar();
          toolbar.setFloatable(false);
          toolbar.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
          toolbar.setMaximumSize(new Dimension(frame.getWidth(), frame.getHeight()));
          frame.getContentPane().add(toolbar, BorderLayout.NORTH);
  
          Component horizontalGlue = Box.createHorizontalGlue();
          toolbar.add(horizontalGlue);
  
          label_1 = new JLabel(" 1 ");
          toolbar.add(label_1);
  
          textField_1 = new JTextField();
          textField_1.setColumns(9);
          textField_1.setMaximumSize(textField_1.getPreferredSize());
          toolbar.add(textField_1);
  
          label_2 = new JLabel(" 2 ");
          toolbar.add(label_2);
  
          textField_2 = new JTextField();
          textField_2.setColumns(9);
          textField_2.setMaximumSize(textField_2.getPreferredSize());
          toolbar.add(textField_2);
      }
  }
  </code></pre>
  
  <p>Notice I am using "system" look and feel.  In Windows 7, it displays perfectly.  The textfields size automatically to their maximum size, and the horizontal glue to their left grows as much as it can, forcing them to be right aligned.</p>
  
  <p><img src="https://i.imgur.com/UmlyOPz.png" alt="enter image description here"></p>
  
  <p>However, in Linux (Ubuntu 12.04 if it matters), it ends up way different.  The textfields scroll right off the frame!  The horizontal glue sizes itself too large.</p>
  
  <p><img src="https://i.imgur.com/J4hEJ2P.png" alt="enter image description here"></p>
  
  <p>I've tried several other different ways to get it to display properly in both, with no luck.  In fact, the only way I can get it to display properly in Linux is to remove all the stylings of the textfield (max width, columns, etc), and then it succeeds in not scrolling off the frame, but it is useless since it has only a few pixels of width.</p>
  
  <p>As a sidenote, I haven't even got a chance to try on a Mac OS, but I'd be curious how <em>that</em> turns out.</p>