How can I align text in a BufferedImage as columns?

Aneesh Vijendran

I am using BufferedImage and Graphics2D to generate a GIF image, but I am struggling to have the layout like in the picture below. I am not even sure if it's possible at all.

The GIF will be animated and the values in Heading3 will change. I've created the code to generate the GIF, but I can't really get this layout. I looked into TextLayout and LineBreakMeasurer, but am not getting the desired o/p. The text should scale based on the image size (which I've got working), but that's key as well.

Any tips?

enter image description here

Andrew Thompson

HTML can be used in Swing components which support rich text, like JLabel. The label can be painted onto an image.

This HTML/CSS should do the trick.

.num {
    color: rgb(0,0,255);
}
td {
    text-align: center;
    padding: 10px;
}
<table border=0 cellspacing=0>
<tr>
<td>
HEADING1<br>
<span class='num'>103</span>
</td>
<td>
HEADING2<br>
<span class='num'>76</span>
</td>
<td>
HEADING3<br>
<span class='num'>64</span>
</td>
</tr>

Edit 1:

Can't use HTML as I have custom fonts and it won't use the fonts correctly.

To use a custom font in HTML, it needs to be (imported and) registered with the GraphicsContext as shown in this answer.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I align the columns of a space separated table in Bash?

How can I align the columns of tables in Bash?

How Can I Align a Text Using execCommand

How can I align checkbox with text to right side of the screen?

How can I left and right align text to center?

How I can align icon next to text of MaterialButton with defined padding?

How can I align a <svg> element with text?

how can I align a button with text area?

How can I left align the extra columns in an Xpages Data View

How can I align text/images from an adapter?

How can I 'align right' the results of Excel's "Text to Columns" feature?

How can I wrap text into two columns?

How can I align text in a button

How can I get the headers to align properly with the columns of the form?

How can I vertically align my status bar item text?

How can I vertically align all the content including borders in the columns?

How can I align my images with the text?

How can I align text and an image horizontally?

How can I vertically align all elements in a list of text?

How can I align the tag with the displayed text?

How can I center align text with hyperlinks in it?

How can I align columns vertically in python?

How can I vertically align list items across columns when item text wraps?

How can I align iconbutton and text?

How can I align columns across multiple tables?

How Can I align Text In Center

How can I convert text to columns with Python?

How can I left align text in a TextButton?

How can I right align column with text and input?