Hello, this is my first post on the mailing list - please point me tot he right places, if i'm off topic.
I have an issue with tab stops in a JTextArea. The behaviour is very similar to the bug JDK-8187957, which was fixed for JDK10. I'm using JDK11 and see the same (wrong) behaviour in my code. After some tests i could confirm, that the bug was fixed for a JTextArea without line wrapping. But calling JTextArea::setLineWrap(true) leads again to the false behaviour. So in a next step I cloned the git Source repository and examined the patch for the Bug. Besides adding a testcase (TestTabSize.java) the fix is changing some float calculation to int: ================================================ commit 0da4c70d2d542d8ff37ee34e4878829af696b694 Author: Prasanta Sadhukhan <[email protected]> Date: Tue Nov 14 10:32:31 2017 +0530 8187957: Tab Size does not work correctly in JTextArea Reviewed-by: ssadetsky, serb diff --git a/src/java.desktop/share/classes/javax/swing/text/PlainView.java b/src/java.desktop/share/classes/javax/swing/text/PlainView.java index 9d1b4fc..6aabc24 100644 --- a/src/java.desktop/share/classes/javax/swing/text/PlainView.java +++ b/src/java.desktop/share/classes/javax/swing/text/PlainView.java @@ -646,7 +646,7 @@ public class PlainView extends View implements TabExpander { if (tabSize == 0) { return x; } - float ntabs = (x - tabBase) / tabSize; + int ntabs = (int) ((x - tabBase) / tabSize); return tabBase + ((ntabs + 1) * tabSize); } ================================================ So in PlainView.java one line was changed. I can see in the source code, that the same (false) line exists in the class WrappedPlainView - which is used as the rendering class, when setLineWrap(true) was called. I think the same fix should be applied to the WrappedPlainView. I could not confirm this fix, because i'm not able to easily build / change the java.desktop module. The issue is reproducible with the following code (adopted from the mentioned bug): ------------- BEGIN CODE ------------------ 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 ); // use WrappedPlainView as renderer 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 CODE ------------------ So my question: Can somebody easily confirm the problem? And if the answer is yes, what are the next steps (creating a bug report - but who and how ;-) ?) Best regards, David
