javahtmlswingjtextpanejeditorpane

What are the limits of functionality for JTextPane or JEditorPane with text/html content type?


I am using a JTextPane that displays text with HTML. I noticed that the text pane doesn't display some options.

<html>
<head>
<style>
body {
  margin-left: 10px;
  margin-right: 10px;
  line-height:2px;
}
.font1 { font-family: "Lucida Console"; }
.font2 { font-family: "Times New Roman"; }
.left {text-align: left;}
.center{text-align: center;}
.right {text-align: right;}
</style>
</head>
<body>
<p class="font2 center">Fecha 15-03-2021 12:54</p>
<p class="font1 left">Tarjeta: </p>
<p class="font2 center">B. Sencilo</p>
<p class="font2 center">.40 €</p>
<p class="font2 center">Incluido IVA y SOV</p>
<p class="font1 left">Línea 1 Viaje: 1</p>
<p class="font1 left">Origen: Avda. de las Postas - Lorenza Corea</p>
<p class="font1 left">Destino: San Andrés</p>
<p class="font1 left">Bus: 6 Pupitre: 9</p>
<p class="font1 left">N. bilete: 57029-078 0JW1</p>
<p class="center"><img src="file:qrcode_150.png"></p>
<p class="font2 center">Consérvese a disposición de los empleados que lo soliciten</p>
<p class="center">-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -</p>
</body>
</html>

As seen in the code snippet, there should be different parts of the text with a different font. However neither the text pane nor the JEditorPane seem to be able to do this, they will just use the default font. I can change the font of the text, but it would be the same font for all of it. Also the line-height also doesn't work, it sets to a default height and can't be changed.

My guess is that there are things that they can't process, but I can't find any information about it. I would appreciate some information or documentation about what can and cannot be done in text panes or editor panes.

Note: my code may seem messy because it is generated by the Java code.


Solution

  • Found it, the css class is the responsible of the interpretation of the code. It is limited to the properties listed there.