Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6741368

in Nimbus L&F text is cut off in JTextField using GridbagLayout & insets

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • None
    • 6u10
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.6.0_10-rc"
      Java(TM) SE Runtime Environment (build 1.6.0_10-rc-b28)
      Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

      javac 1.6.0_10-rc

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Graphics Card: NVIDIA Quadro NVS 280 SD
      resolution set at: 1280 x 1024 pixels
      32-bit color

      A DESCRIPTION OF THE PROBLEM :
      Using Nimbus Look and Feel, the text displayed in a JTextField is cut off at the bottom. The same program displays correctly using the default Metal L&F and Windows L&F. The JTextField's GridBag constraints are:

              tfUserName = new JTextField();
              tfUserName.setPreferredSize(new Dimension(100, 25));
              tfUserName.setMinimumSize(new Dimension(80, 25));
              tfUserName.setAlignmentY(JTextField.TOP_ALIGNMENT);
              gridBagConstraints.weightx = 1.0;
              gridBagConstraints.weighty = 1.0;
              gridBagConstraints.gridwidth = 1;
              gridBagConstraints.gridheight = 1;
              gridBagConstraints.insets = new Insets(4,4,-4,4);
              gridBagConstraints.insets.bottom = 4;
              gridBagConstraints.gridx = 1;
              gridBagConstraints.gridy = 3;
              gridBagConstraints.anchor = GridBagConstraints.SOUTHWEST;
              gridBagLayout.setConstraints(tfUserName, gridBagConstraints);


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The source code entered below includes two classes, MvMain and LoginPanel. In MvMain.initApp() is a call to UIManager.setLookAndFeel(). This sets the Look and Feel to Nimbus L&F. You can change which L&F is set in order to compare the painting of the JTextField with the default or other L&F's. MvMain displays the name of the look and feel in use in the window title.

      When the program is running, type the string: "joypaqg" (i.e. any letters that have descending parts) in the Username JTextField. You will see that the lower parts of letters with descending parts are missing.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected to see all of the letters that I type, including their descending parts.
      ACTUAL -
      All lower-case letters with descending parts are missing their descending parts.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No error messages are produced. The displayed text is just incorrectly painted.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.applet.Applet;
      import java.applet.AppletContext;
      import java.awt.Color;
      import java.awt.Cursor;
      import java.awt.Dimension;
      import java.awt.Frame;
      import java.awt.Rectangle;
      import java.awt.Toolkit;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.event.MouseAdapter;
      import java.net.MalformedURLException;
      import java.net.URL;
      import java.util.Enumeration;
      import java.util.StringTokenizer;

      import java.awt.BorderLayout;
      import javax.swing.JOptionPane;
      import javax.swing.JFrame;
      import javax.swing.JPopupMenu;
      import javax.swing.ProgressMonitor;
      import javax.swing.SwingUtilities;
      import javax.swing.UIManager;

      public class MvMain extends JFrame
      {
          private static final long serialVersionUID = -6271057902984678813L;
          
          protected Dimension SCREEN_SIZE = null;
          private JFrame loginFrame;


          private String presetUserName = null;
          private String presetPassword = null;
          
          // main
          public static void main(String args[])
          {
              
              new MvMain();
          }

          // Mv
          public MvMain()
          {
              this(null);
          }

          public MvMain(String withUserName, String withPassword)
          {
              super("Nimbus JTextField Test");

             presetUserName = withUserName;
             presetPassword = withPassword;

             initApp(null);
          }

          // Mv
          public MvMain(AppletContext withAppletContext)
          {
              super("Nimbus JTextField Test");
              initApp(withAppletContext);
          }

          private void initApp(AppletContext withAppletContext)
          {
              /**
               * ensures that menu's rise above any heavy weight elements
               * This is critical for WebRenderer.
               */
              JPopupMenu.setDefaultLightWeightPopupEnabled(false);

              try {
              
                  UIManager.setLookAndFeel(
                      "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
       // "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

              } catch (Exception e) { }


              Color base = new Color(236,233,216);


              // launch login
              launchLoginFrame();

          }


          // getLoginFrame
          public JFrame getLoginFrame()
          {
              return loginFrame;
          }

          // launchLoginFrame
          private void launchLoginFrame()
          {
              setLoginFrame(new JFrame("L&F: " + UIManager.getLookAndFeel().getName()));
              getLoginFrame().setSize(300,250);
              getLoginFrame().getContentPane().add(new LoginPanel( getLoginFrame(),null),BorderLayout.CENTER);

              if ((presetUserName != null) && (presetPassword != null))
              {
                // test harness -- bypass the login dialog box!!!!
                return;
              }

              getLoginFrame().setVisible(true);

          }



          // setLoginFrame
          protected void setLoginFrame(JFrame value)
          {
              loginFrame = value;
          }


      }

      import java.awt.BorderLayout;
      import java.awt.Color;
      import java.awt.Component;
      import java.awt.Dimension;
      import java.awt.FlowLayout;
      import java.awt.Frame;
      import java.awt.GridBagConstraints;
      import java.awt.GridBagLayout;
      import java.awt.Insets;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.event.MouseEvent;
      import java.awt.event.MouseListener;

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      import javax.swing.JPasswordField;
      import javax.swing.JTextField;
      import javax.swing.SwingConstants;

      public class LoginPanel extends JPanel {

      private static final long serialVersionUID = 1612748376439346956L;
      public LoginPanel(
              JFrame withLoginFrame,
              String withUserName)
          {
      super();
              
              setVisible(true);
              
              setLoginFrame(withLoginFrame);
              setLayout(new BorderLayout(0,2));

              // components
              GridBagLayout gridBagLayout;
              GridBagConstraints gridBagConstraints;

              gridBagLayout = new GridBagLayout();
              gridBagConstraints = new GridBagConstraints();
              JPanel body_wrapper = new JPanel(gridBagLayout);
              
              JLabel lblBannerImage = new JLabel("LOGO_BANNER");
              JLabel lblVersion = new JLabel("Version: " + "5.5");
              JLabel lblUserName = new JLabel("User Name:");
              JLabel lblPassword = new JLabel("Password:");
              
              JLabel tunnelHrefLabel = new JLabel("Proxy");
              tunnelHrefLabel.setForeground(Color.BLUE);
              tunnelHrefLabel.addMouseListener(new LoginMouseListener(this));
              
              tfUserName = new JTextField();
              tfUserName.setPreferredSize(new Dimension(100, 25));
              tfUserName.setMinimumSize(new Dimension(80, 25));
              tfUserName.setAlignmentY(JTextField.TOP_ALIGNMENT);
              lblUserName.setLabelFor(tfUserName);
              tfUserName.setVisible(true);
              tfPassword = new JPasswordField();
              tfPassword.setPreferredSize(new Dimension(100, 25));
              tfPassword.setMinimumSize(new Dimension(80, 25));
              tfPassword.setAlignmentY(JTextField.TOP_ALIGNMENT);
              lblPassword.setLabelFor(tfPassword);
              tfPassword.setVisible(true);
              
              btnCancel = new JButton("BTN_CANCEL");
              btnCancel.setPreferredSize(new Dimension(40,25));

              btnLogin = new JButton("BTN_LOGIN");
              btnLogin.setPreferredSize(new Dimension(40,25));


              // layout

              gridBagConstraints.weightx = 1.0;
              gridBagConstraints.weighty = 1.0;
              gridBagConstraints.gridwidth = 1;
              gridBagConstraints.gridheight = 1;
              gridBagConstraints.insets = new Insets(4,4,-4,4);

              gridBagConstraints.gridx = 0;
              gridBagConstraints.gridy = 0;
              gridBagConstraints.gridwidth = 2;
              gridBagConstraints.anchor = GridBagConstraints.SOUTH;
              gridBagLayout.setConstraints(lblBannerImage, gridBagConstraints);
              body_wrapper.add(lblBannerImage);

              gridBagConstraints.insets.bottom = 8;

              lblVersion.setForeground(Color.darkGray);
              gridBagConstraints.gridx = 0;
              gridBagConstraints.gridy = 1;
              gridBagConstraints.gridwidth = 2;
              gridBagConstraints.anchor = GridBagConstraints.CENTER;
              gridBagLayout.setConstraints(lblVersion, gridBagConstraints);
              body_wrapper.add(lblVersion);

              gridBagConstraints.insets.bottom = 4;

              gridBagConstraints.gridx = 0;
              gridBagConstraints.gridy = 3;
              gridBagConstraints.gridwidth = 1;
              gridBagConstraints.anchor = GridBagConstraints.SOUTHEAST;
              gridBagLayout.setConstraints(lblUserName, gridBagConstraints);
              body_wrapper.add(lblUserName);

              gridBagConstraints.gridx = 1;
              gridBagConstraints.gridy = 3;
              gridBagConstraints.anchor = GridBagConstraints.SOUTHWEST;
              gridBagLayout.setConstraints(tfUserName, gridBagConstraints);
              body_wrapper.add(tfUserName);

              gridBagConstraints.gridx = 0;
              gridBagConstraints.gridy = 4;
              gridBagConstraints.anchor = GridBagConstraints.NORTHEAST;
              gridBagLayout.setConstraints(lblPassword, gridBagConstraints);
              body_wrapper.add(lblPassword);

              gridBagConstraints.gridx = 1;
              gridBagConstraints.gridy = 4;
              gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
              gridBagLayout.setConstraints(tfPassword, gridBagConstraints);
              body_wrapper.add(tfPassword);

              JPanel bottom_wrapper = new JPanel(new FlowLayout(FlowLayout.RIGHT, 4, 1));
              bottom_wrapper.add(btnLogin);
              bottom_wrapper.add(btnCancel);
              JPanel buttonBottom = new JPanel(new BorderLayout());
              buttonBottom.add(bottom_wrapper, BorderLayout.CENTER);

              gridBagConstraints.gridx = 0;
              gridBagConstraints.gridy = 5;
              gridBagConstraints.gridwidth = 2;
              gridBagConstraints.anchor = GridBagConstraints.NORTHEAST;
              gridBagLayout.setConstraints(buttonBottom, gridBagConstraints);
              body_wrapper.add(buttonBottom);

              if (withUserName != null) {
                tfUserName.setText(withUserName);
                tfUserName.setEnabled(false);
              }
              
              add(body_wrapper, BorderLayout.CENTER);
          
              JPanel hyperPanel = new JPanel(new BorderLayout());
              hyperPanel.add(tunnelHrefLabel, BorderLayout.EAST);
              add(hyperPanel, BorderLayout.SOUTH);
          }


          /**
           * Sets the focus and default button when the panel is initially displayed.
           */
          public void setInitialFocus(){
              tfUserName.requestFocus();
              loginFrame.getRootPane().setDefaultButton(btnLogin);
          }

          // setButtonsEnabled
          public void setButtonsEnabled(boolean value){
              btnLogin.setEnabled(value);
              btnCancel.setEnabled(value);
          }


          // getLoginFrame
          public JFrame getLoginFrame(){
              return loginFrame;
          }

          // getLoginPanel
          public JPanel getLoginPanel(){
              return LoginPanel.this;
          }

          // getUserNameField
          public JTextField getUserNameField(){
              return tfUserName;
          }

          // getPasswordField
          public JPasswordField getPasswordField(){
              return tfPassword;
          }


          class LoginMouseListener implements MouseListener
          {
              private JPanel parent;
              public LoginMouseListener(JPanel parent)
              {
                  super();
                  this.parent=parent;
              }
              
              public void mouseClicked(MouseEvent e)
              {
                  Component c = (Component) parent;
                  while (!(c instanceof Frame))
                  {
                      c = c.getParent();
                  }
              }
              
              public void mouseExited(MouseEvent e)
              {}
              
              public void mouseReleased(MouseEvent e)
              {}
              public void mousePressed(MouseEvent e)
              {}
              public void mouseEntered(MouseEvent e)
              {}
          }

          // setLoginFrame
          protected void setLoginFrame(JFrame value){
              loginFrame = value;
          }

          private JTextField tfUserName;
          private JPasswordField tfPassword;
          private JFrame loginFrame;
          private JButton btnLogin;
          private JButton btnCancel;

          
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      We have no workaround that allows the GUI to look good.

      We are also having problems with the painting of JTextPane text in a Document used inside a JTable cell. In this case, more of the text disappears at the bottom, not just the letters' descending parts. These two problems are preventing us from using Nimbus L&F for our application. We will have to find some other, 3rd party L&F for the new release of our product.

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: