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

Tab Size does not work correctly in JTextArea with setLineWrap on

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b13
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        With tab size set to 8 and setLineWrap on, the text are not aligned. Attached is screenshot of expected aligned text and bad aligned text for below program

        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.setLineWrap( true );
                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);});
            }
        }

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                psadhukhan Prasanta Sadhukhan
                Reporter:
                psadhukhan Prasanta Sadhukhan
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: