Bug Table text alignment with print_html() doesn't work properly

philmasterplus

Active member
I've been trying to right-align table cells in the KoLmafia CLI with print_html() but couldn't get it to work properly.

Code:
print_html('<table style="border-width: 1px;"><tr style="background-color: #CCCCCC;"><th style="border-width: 1px;">Long Column Title</th><th style="border-width: 1px;">Another Long Column Title</th></tr><tr><td style="border-width: 1px;">normal text</td><td style="border-width: 1px; text-align: left;">left-aligned</td></tr><tr><td style="border-width: 1px; text-align: center;">center-aligned</td><td style="border-width: 1px; text-align: right;">right-aligned</td></tr></table>');

Most of the time, the table cells are simply center-aligned, regardless of the text-align value. When I use print_html() multiple times, previous tables are occasionally re-aligned properly. See:

glitchy.png
 

Veracity

Developer
Staff member
Yes. Java's internal HTML renderer really doesn't handle styles very well. I spent a number of hours trying to get a text field to wrap in a table cell when there is no space in the text (as is the case for some properties, which makes "prefref" problematic), consulting a variety of online articles, and failed. Perhaps there is something we can do to StyledChatBuffer (which is what is used for the display pane in the gCLI, but I did not figure it out. In particular, after every attempt to put "style" attributes in table cells failed, I tried to add a "StyleSheet" object (available since Java 7, and we require Java 8 or later) to the text area but couldn't get any of the online examples using such to work, either. I ran out of time and patience and gave up.

For reference, which version of Java are you using? The "About KoLmafia" item in the KoLmafia menu will tell you.
 

MCroft

Developer
Staff member
Well, I've barely started learning Swing, but the online advice if you want newer HTML is to embed a JFX web view in your swing app via JFXpanel.

The down side is that it was split off in Java 11 and requires a platform-specific download from Gluon to get it back. (like Nashorn, but still ugh). I think that that's not really what we want, long term.
 

MCroft

Developer
Staff member
The previous thing is probably coming from your class values.

At a guess, it may be having a problem because it's not scoped inside an
Code:
<html><body>...</body></html>
tagset. Your TextEditor can see the prior elements and they have the same classnames.

Either that, or try it with unique ids instead of classes, and regenerate them between prints.

Edit: on test, I don't see the inappropriate assignment, but I only ran it 3-4 times.
 
Last edited:
Top