0

I am trying to create vertical text in a jlabel, and since there isn't a method for it in java i am using HTML, but it doesn't wanna work.

Here is a html document that displays the same code and here it is vertical.

<html>
    <p class="fasz">
        <p style="text-orientation:  sideways-right;writing-mode: vertical-rl">
    Picsa
    </p>
</html>

Here is a java example:

package javaapplication48;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class JavaApplication48 {

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(null);
        frame.setSize(500, 500);
        frame.setVisible(true);

        JLabel label = new JLabel();
        label.setText("<html>"
                + " <p class=\"fasz\">"
                + "        <p style=\"text-orientation:  sideways-right;writing-mode: vertical-rl\">"
                + " Picsa"
                + " </p>"
                + "</html>");
        frame.add(label);
        label.setBounds(0, 0, 200, 200);
        
        JLabel ctrl =new JLabel();
        ctrl.setText("<html>"
                + " <p class=\"fasz\">"
                + "        <p style=\"color:red\">"
                + " Picsa"
                + " </p>"
                + "</html>");
        ctrl.setBounds(0, 0, 200, 300);
        frame.add(ctrl);
        ctrl.updateUI();
    }

}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
error13660
  • 120
  • 7
  • https://stackoverflow.com/questions/92781/how-do-i-present-text-vertically-in-a-jlabel-java-1-6 this will answer your question. – SAQ Sep 06 '20 at 17:06
  • You can try using the [Rotated Icon](https://tips4java.wordpress.com/2009/04/06/rotated-icon/). This is a more flexible approach since it can be used with any component that can display an Icon, not just a JLabel. You will also need the `TextIcon` class from the blog. – camickr Sep 06 '20 at 17:33
  • The second gentleman got it, thank you @camickr – error13660 Sep 06 '20 at 18:16
  • 1
    Swing’s HTML renderer is quite old: it only supports HTML 3.2 and CSS 1.0. It does not support the `text-orientation` CSS property at all. – VGR Sep 06 '20 at 21:33

0 Answers0