How to rendering fraction in Swing JComponents

后端 未结 6 946
清酒与你
清酒与你 2020-11-29 12:53

Basically Swing JComponents are able to display numbers in fractions in this form 2 2/3. How can I paint fraction in the nicest form, for example 2⅔?

.<

6条回答
  •  孤城傲影
    2020-11-29 13:51

    Special fonts method:

    The special fonts method might be a really good solution too.

    You are going to need a good font editor.

    Create ten numbers just for the top number of the fraction, a special slash or line symbol for the middle, and ten numbers just for bottom digits.

    The only problem is that it's got to look good and that requires that the spacing of the top/slash/and button all close to together, actually overlapping horizontally. The good news is fonts support this, and a good font editor will. The swing text components probably don't. You need to write your own text component of find a component that already lets you fine position the fonts. This is the different between test editing/ word processing and text typography.

    But I also have another idea :)

    You could do fractions with a horizontal bar instead of a diagonal slash.

    123
    ---
    456
    

    This way font need not overlap and can be laid out by the editor in the standard way. The trick is to have the above be three characters next to each other.

    1 2 3
    - - -
    4 5 6
    

    So that's one hundred different characters you need for all combinations.

    The only problem with this (in addition to having to create 100 characters) is if you have and odd number of digits in the top and even in the bottom or vise verse it will look like this:

     12
    ---
    456
    

提交回复
热议问题