How to accurately display string in JComboBox?

109 Views Asked by At

I have an array of strings that represent options in a drop-down menu.

        String[] s_reflection_map = {
                "x=W–1–x mod W                               ",
                "x/W even x=x mod W; odd x=W–1–x mod W, no PI",
                "same, but with Pixel Interpolation          ",
                "x=x mod W/2, y=y mod H/2                    ",
                "x>W–1,x=x mod W else x=W–1–x mod W          ",
                "x<W,x=x mod W//2 else x=W–1–x mod W         ",
                "x/W even,x=x mod W/2;odd x=W–1–x mod W/2    ",
                "x/W even,x=x mod W/2;odd x=(W–1)/2–x mod W/2",
                "simple                                      "
        };

        JComboBox<String> jcb_reflection_map = new JComboBox<>(s_reflection_map);

Minus sign, the character "-" cannot be displayed correctly.

JComboBox shown in configuration JFrame window

Can anyone remind me of why minus is illegal character?

2

There are 2 best solutions below

1
On

The subtraction symbols are encoded as literal Unicode EN DASH' (U+2013) characters, the preferred glyph in a mathematical context. In Java source, substitute the corresponding escape, for example,

"x=W\u20131\u2013x mod W                               ",
0
On

This is the format that works well.

"x = W \u2013 x mod W"