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

Tab Size does not work correctly in JTextArea

    XMLWordPrintable

Details

    • 9
    • b33
    • x86
    • windows_10

    Description

      FULL PRODUCT VERSION :
      java version "9"
      Java(TM) SE Runtime Environment (build 9+181)
      Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      1703 (Compilation 15063.608)

      A DESCRIPTION OF THE PROBLEM :
      The setTabSize of the JTextArea behavior changed in a way that makes a tab to always be replaced by the number of spaces specified as the argument (no matter the position in the text). This is wrong because normal behavior pushes the text so that it starts in the position that is multiple of the size specified as the argument.

      Even when not calling setTabSize and leaving the component with its default value (getTabSize is 8), the problem still occurs. It is impossible to view a text file aligned with tabs the same way as viewed, for example, in notepad or notepad++.

      The program compiled with JDK 8 works well in JRE 8 but not in JRE 9.

      REGRESSION. Last worked in version 8u144

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_144"
      Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
      Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a frame with a JTextArea.

      2. Set a Monospaced font (usually default, but set it to be sure as it may be different in some platforms/look and feel).

      3. Set some text with tabs like this in the JTextArea:
      #################################################
      # Some Text #
      # Some Other Much Longer Text #
      #################################################
      (this should be well aligned with tab size = 8)

      4. Compile with JDK 8.

      5. Run in JRE 8: Works well (text well aligned).

      6. Run in JRE 9: Works incorrectly (text unaligned).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Since we are using a monospaced font, the text in the JTextArea should be in a well aligned box of # (when using tab size = 8).
      ACTUAL -
      The output is not well aligned.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No errors.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class TabTestJFrame extends javax.swing.JFrame {
          private javax.swing.JScrollPane jScrollPane1;
          private javax.swing.JTextArea jTextArea1;
          
          public TabTestJFrame() {
              initComponents();
              jTextArea1.setTabSize(8);
          }

          private void initComponents() {

              jScrollPane1 = new javax.swing.JScrollPane();
              jTextArea1 = new javax.swing.JTextArea();

              setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

              jTextArea1.setFont(new java.awt.Font("Monospaced", 0, 10));
              jTextArea1.setText("#################################################\n# Some Text\t\t\t\t\t#\n# Some Other Much Longer Text\t\t\t#\n#################################################");
              jScrollPane1.setViewportView(jTextArea1);

              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addContainerGap()
                      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
                      .addContainerGap())
              );
              layout.setVerticalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addContainerGap()
                      .addComponent(jScrollPane1)
                      .addContainerGap())
              );

              pack();
          }

          public static void main(String args[]) {
              System.out.println("Java Version: " + System.getProperty("java.specification.version"));
              java.awt.EventQueue.invokeLater(() -> {new TabTestJFrame().setVisible(true);});
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      There is no work around that I know of.

      SUPPORT :
      YES

      Attachments

        1. 8u144.PNG
          8u144.PNG
          12 kB
        2. 9.PNG
          9.PNG
          5 kB
        3. TabTestJFrame.java
          2 kB

        Activity

          People

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: