Published 19 Sep, 2022

Java - Eclipse - How do I create a table in the comment section of class/method?

Category Java
Modified : Oct 03, 2022
68

I want to use <\tbody>, <\tr> and <\td> to create a table in the comment section of a method :

<tbody>
<tr>
    <td>personId</td>
    <td>y</td>
    <td>identifiant</td>
    <td>C16</td>
    <td>String</td>
</tr>
<tr>
    <td>lastName</td>
    <td>n</td>
    <td>nom</td>
    <td>C32</td>
    <td>String</td>
</tr>
</tbody>

Unfortunately it doesn't work as I don't see a table in the Java doc, just the following :

personId y identifiant C16 String lastName n nom C32 String

What should I do ? The <\table> tag is not proposed by Eclipse and if I use it it doens't change anything. If it matters, I am using eclipse Neon.

Answers

There are 4 suggested solutions here and each one has been listed below with a detailed description. The following topics have been covered briefly such as Java, Html Table, Comments, Eclipse. These have been categorized in sections for a clear and precise explanation.

12

First, you should specify the table element before tbody to be conform to the table element :

Permitted content

In this order:

  • an optional caption element,

  • zero or more colgroup elements,

  • an optional thead element,

  • either one of the following:

    • zero or more tbody elements

    • one or more tr elements

  • an optional tfoot element

Second, you don't need Eclipse wizard or tool to document your Javadoc with HTML tags.
Just write your HTML content in a javadoc comment :

/**
<table><tbody>
<tr>
    <td>personId</td>
    <td>y</td>
    <td>identifiant</td>
    <td>C16</td>
    <td>String</td>
</tr>
<tr>
    <td>lastName</td>
    <td>n</td>
    <td>nom</td>
    <td>C32</td>
    <td>String</td>
</tr>
</tbody></table>
 */
public void foo(){
  ...
}

And it should display it in a tabular way in the javadoc view or generation:

void foo()

personId y identifiant C16 String

lastName n nom C32 String


51

As an alternative variant use <pre></pre> tag to render markdown tables

/**
 * Description
 * <pre>
 | Key   |    Value    |
 |-------|-------------|
 | 1     | Value1      |
 | 2     | Value2      |
 *</pre>
 */

Generates:


35

You can use this tool and specify the output style is HTML.


11

You can use markdown style table. It's more readable than HTML one for developers.

Example:

/**
 *  2 Device Connected possible states matrix
 *
|         | DIALING | ON_HOLD | RINGING | ON_CALL | IDLE |
|---------|---------|---------|---------|---------|------|
| DIALING |   --    | YES     | YES     | YES     | YES  |
| ON_HOLD |  YES    | YES     | YES     | YES     | YES  |
| RINGING |  YES    | YES     | YES     | YES     | YES  |
| ON_CALL |  YES    | YES     | YES     | --      | YES  |
| IDLE    |  YES    | YES     | YES     | YES     | YES  |
 */

You can generate a table in markdown from here

https://www.tablesgenerator.com/markdown_tables#