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

[macosx] Label shortening via " ... " broken when String contains combining diaeresis

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7, 7u21
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b52
    • OS:
      os_x

      Backports

        Description

        FULL PRODUCT VERSION :
        java version " 1.7.0_21 "
        Java(TM) SE Runtime Environment (build 1.7.0_21-b12)
        Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Darwin Macintosh-7.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64

        A DESCRIPTION OF THE PROBLEM :
        When a JLabel does not fit into the allotted space, the String it contains is automatically shortened by truncating the String and appending an ellipsis character ( " ... " ). This works beautifully for regular Strings.
        But as soon as the String contains a combining diaeresis, e.g. to turn a 'u' into a '?', the way Strings are shortened changes. The String is not truncated anymore after the last character that still fits into the available space, but at the last character that still fits AND is a punctuation or whitespace character. This looks odd especially when a JTable lists URLs, of which only some contain a diaeresis.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        See source code for reproduction.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        JLabels with and without diaeresis should be shortened exactly the same way.
        ACTUAL -
        JLabels with diaeresis are shortened differently than the one with.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import javax.swing.*;
        import javax.swing.table.DefaultTableModel;

        /**
         * Shortening via " ... " is broken for Strings containing a combining diaeresis.
         */
        public class TestBadBreak {

            public static void main(String[] args) {
                final DefaultTableModel model = new DefaultTableModel(new Object[]{ " With " , " Without " }, 2);
                final String stringWithCombiningDiaeresis = " http://withCombiningDiaeresis.aaaaaaaaa.com/a\u0308aaaaaaaaaaaa/ aaaaaaaaaaaaaa/aaaaaaaaaaaa/ " ;
                final String stringWithoutCombiningDiaeresis = " http://withoutCombiningDiaeresis.aaaaaaaaa.com/\u00E4aaaaaaaaaaaa/ aaaaaaaaaaaaaa/aaaaaaaaaaaa/ " ;
                model.setValueAt(stringWithCombiningDiaeresis, 0, 0);
                model.setValueAt(stringWithoutCombiningDiaeresis, 0, 1);
                final JTable table = new JTable();
                table.setModel(model);
                final JFrame frame = new JFrame();
                frame.getContentPane().add(new JScrollPane(table));
                frame.setBounds(200, 200, 300, 300);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        frame.setVisible(true);
                    }
                });
            }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        One can use the java.text.Normalizer to remove diaeresis.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                serb Sergey Bylokhov
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: