GianniTee
GianniTee

Reputation: 177

How to accurately display string in JComboBox?

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?

Upvotes: 1

Views: 99

Answers (2)

GianniTee
GianniTee

Reputation: 177

This is the format that works well.

"x = W \u2013 x mod W"

Upvotes: 0

trashgod
trashgod

Reputation: 205775

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                               ",

Upvotes: 3

Related Questions