1

I am meeting undesired line breaks when I put Hindi text in html tags.

Since I deem this a rather common problem in India, I only wonder why I am not finding something about this issue online nor in the bug data base.

Here's my demo code:

import java.awt.*;
import javax.swing.*;

public class UndesiredLineBreak extends JFrame {
  public static final long serialVersionUID = 1L;

  public UndesiredLineBreak() {
    setSize(800, 230);
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setLayout(new GridLayout(0, 2, 3, 3));
    String s=
    "\u0905\u0902\u0924\u093F\u092E "+
    "\u0936\u092C\u094D\u0926 \u0915\u0947 \u091A\u0941\u0928\u093E\u0935 "+
    "\u0915\u0947 \u092C\u093E\u0926 \u0935\u093F\u0902\u0921\u094B "+
    "\u0915\u094B "+
    "\u092C\u0928\u094D\u0926 \u0915\u0930\u0928\u0947 \u0915\u0940 "+
    "\u0906\u0935\u0936\u094D\u092F\u0915\u0924\u093E "+
    "\u0939\u0948\u0964";
    add(new JButton(s));
    add(new JLabel("OK"));
    String s1= "<html>"+s+"</html>";
    add(new JButton(s1));
    add(new JLabel("Html moves last character."));
//  Insert <br>
    int i= s1.indexOf("\u092C\u0928");
    s1= s1.substring(0, i-1) + "<br>" + s1.substring(i);
    add(new JButton(s1));
    add(new JLabel("<br> moves preceding word."));
    setVisible(true);
  }

  public static void main(String args[]) {
    SwingUtilities.invokeLater(UndesiredLineBreak::new);
  }
}
Robin Green
  • 32,079
  • 16
  • 104
  • 187
Jörg
  • 499
  • 1
  • 5
  • 10
  • 1
    I don't see any difference between your first example, and the example using html tags? https://i.imgur.com/Zt1WZDJ.png – explv Apr 27 '18 at 11:09
  • 1
    Thank you for running the code, @explv. Looking at the picture you made, I see exactly what I expect my code to show. I'm using Win-10 with a user defined screen scaling of 125 %. So I changed it to 100 % and lo and behold! that works. – Jörg Apr 27 '18 at 18:41
  • So far I never had this problem, and thus the new question is, whether java made changes in handling screen scaling. But this, I suppose, should go in a separate thread. – Jörg Apr 27 '18 at 18:54

0 Answers0