matthiasblaesing commented on pull request #2482:
URL: https://github.com/apache/netbeans/pull/2482#issuecomment-721061353


   @errael what is wrong with the "draw till next character" approach? The API 
addition be it necessary or not, will not fix the existing users. This is the 
code I used to see what Swing reports for `modelToView`:
   
   ```java
   public class JTextComponentWidth {
   
       public static void main(String[] args) throws BadLocationException {
        JFrame jframe = new JFrame("Test");
        jframe.setSize(1024, 768);
        jframe.setLayout(new BorderLayout());
        jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JTextArea textArea = new JTextArea();
        textArea.setCaret(new DefaultCaret() {
   
        });
        Document doc = textArea.getDocument();
        doc.remove(0, doc.getLength());
        for (char i = 1; i < 128; i++) {
            doc.insertString(doc.getLength(), Character.toString(i), null);
        }
        jframe.add(new JScrollPane(textArea));
        jframe.setVisible(true);
        SwingUtilities.invokeLater(() -> {
            for (char i = 0; i <= doc.getLength(); i++) {
                try {
                    Rectangle r1 = textArea.modelToView(i);
                    Rectangle r2 = textArea.modelToView(i + 1);
                    System.out.println(((int) i + 1) + ": " + r1 + " " + (r2.x 
- r1.x));
                } catch (BadLocationException ex) {
                    
Logger.getLogger(JTextComponentWidth.class.getName()).log(Level.SEVERE, null, 
ex);
                }
            }
        });
        SwingUtilities.invokeLater(() -> {
            try {
                System.out.println(doc.getLength());
                System.out.println(textArea.modelToView(doc.getLength() - 1));
                System.out.println(textArea.modelToView(doc.getLength()));
                System.out.println(textArea.modelToView(doc.getLength() + 1));
            } catch (BadLocationException ex) {
                
Logger.getLogger(JTextComponentWidth.class.getName()).log(Level.SEVERE, null, 
ex);
            }
        });
       }
   }
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to