Hi David, I was able to get the result by running your example on a freshly build JDK. The fix that you suggested should be applied to this line: https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/javax/swing/text/WrappedPlainView.java#L469 (#469). You can contribute to JDK if you want, but I know that it takes some time to build it from sources, prepare the test and the patch.
I think I can create the patch for you, and ask my colleague to create the bug report. But there is a usual difficulty is to cover this issue with a test file. Your example is not bad, no, but how to automate it? š I can try to invest some time to it after I come from vacation and find a spare time. I guess you have about 3-4 weeks to practice with the JDK building and tests writing (jtreg). Kind regards, Vlad From: swing-dev <[email protected]> On Behalf Of David Polock Sent: Freitag, 14. Februar 2020 14:47 To: [email protected] Subject: <Swing Dev> Followup to JDK-8187957 Tab Size does not work correctly in JTextArea 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]<mailto:[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
