usar texto tabla sumar pasar numeral letras insertar hexadecimal generar extendida cómo códigos código convertir como codigos codigo caracteres caracter binario java console

java - texto - tabla ascii pdf



¿Cómo puedo crear una tabla usando ASCII en una consola? (8)

Esto también funciona bastante bien http://sourceforge.net/projects/texttablefmt/ . Apache también tiene licencia.

Me gustaría organizar información como esta:

La información está organizada con celdas, mientras que con System.out.println la información sería muy desorganizada.


Intente utilizar System.out.format() o System.out.printf() ( printf simplemente invoca el format para que ambos métodos den los mismos resultados).

Aquí tiene un ejemplo simple que intentará alinear el texto a la izquierda y rellenar los espacios no utilizados con espacios. Alinear cadena a la izquierda se puede lograr con %-15s , lo que significa que reserva 15 lugares para los datos de cadena ( s ) y comienza a escribir desde la izquierda ( - ). Si desea agregar dígitos, use el sufijo d como %-4d para números máximos de 4 dígitos que deben colocarse en el lado izquierdo de la columna.
Por cierto utilicé %n lugar de /n para representar la secuencia de separador de línea utilizada por el sistema operativo actual, como para Windows, será /r/n .

Puede encontrar más información en la documentación de la clase de formateador .

String leftAlignFormat = "| %-15s | %-4d |%n"; System.out.format("+-----------------+------+%n"); System.out.format("| Column name | ID |%n"); System.out.format("+-----------------+------+%n"); for (int i = 0; i < 5; i++) { System.out.format(leftAlignFormat, "some data" + i, i * i); } System.out.format("+-----------------+------+%n");

salida

+-----------------+------+ | Column name | ID | +-----------------+------+ | some data0 | 0 | | some data1 | 1 | | some data2 | 4 | | some data3 | 9 | | some data4 | 16 | +-----------------+------+


Mi clase que creé específicamente para hacer esto es completamente dinámica: https://github.com/MRebhan/crogamp/blob/master/src/com/github/mrebhan/crogamp/cli/TableList.java

Puedes usarlo así:

TableList tl = new TableList(3, "ID", "String 1", "String 2").sortBy(0).withUnicode(true); // from a list yourListOrWhatever.forEach(element -> tl.addRow(element.getID(), element.getS1(), element.getS2())); // or manually tl.addRow("Hi", "I am", "Bob"); tl.print();

Se verá así con los caracteres unicode (nota: se verá mejor en la consola ya que todos los caracteres son igualmente anchos):

┌─────────┬─────────────────────────────────────────────────────────────────────────┬────────────────────────────┐ │ Command │ Description │ Syntax │ ┢━━━━━━━━━╈━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╈━━━━━━━━━━━━━━━━━━━━━━━━━━━━┪ ┃ bye ┃ Quits the application. ┃ ┃ ┃ ga ┃ Adds the specified game. ┃ <id> <description> <path> ┃ ┃ gl ┃ Lists all currently added games ┃ [pattern] ┃ ┃ gr ┃ Rebuilds the files of the currently active game. ┃ ┃ ┃ gs ┃ Selects the specified game. ┃ <id> ┃ ┃ help ┃ Lists all available commands. ┃ [pattern] ┃ ┃ license ┃ Displays licensing info. ┃ ┃ ┃ ma ┃ Adds a mod to the currently active game. ┃ <id> <file> ┃ ┃ md ┃ Deletes the specified mod and removes all associated files. ┃ <id> ┃ ┃ me ┃ Toggles if the selected mod is active. ┃ <id> ┃ ┃ ml ┃ Lists all mods for the currently active game. ┃ [pattern] ┃ ┃ mm ┃ Moves the specified mod to the specified position in the priority list. ┃ <id> <position> ┃ ┃ top kek ┃ Test command. Do not use, may cause death and/or destruction ┃ ┃ ┃ ucode ┃ Toggles advanced unicode. (Enhanced characters) ┃ [on|true|yes|off|false|no] ┃ ┗━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Y con caracteres Unicode desactivados (omita el .withUnicode (verdadero)):

Command | Description | Syntax --------+-------------------------------------------------------------------------+--------------------------- bye | Quits the application. | ga | Adds the specified game. | <id> <description> <path> gl | Lists all currently added games | [pattern] gr | Rebuilds the files of the currently active game. | gs | Selects the specified game. | <id> help | Lists all available commands. | [pattern] license | Displays licensing info. | ma | Adds a mod to the currently active game. | <id> <file> md | Deletes the specified mod and removes all associated files. | <id> me | Toggles if the selected mod is active. | <id> ml | Lists all mods for the currently active game. | [pattern] mm | Moves the specified mod to the specified position in the priority list. | <id> <position> top kek | Test command. Do not use, may cause death and/or destruction | ucode | Toggles advanced unicode. (Enhanced characters) | [on|true|yes|off|false|no]


Prueba esta alternativa: asciitable .

Ofrece varias implementaciones de una tabla de texto, originalmente usando caracteres ASCII y UTF-8 para bordes.

Aquí hay una tabla de muestra:

┌──────────────────────────────────────────────────────────────────────────┐ │ Table Heading │ ├──────────────────┬──────────────────┬──────────────────┬─────────────────┤ │ first row (col1) │ with some │ and more │ even more │ │ │ information │ information │ │ ├──────────────────┼──────────────────┼──────────────────┼─────────────────┤ │ second row │ with some │ and more │ even more │ │ (col1) │ information │ information │ │ │ │ (col2) │ (col3) │ │ └──────────────────┴──────────────────┴──────────────────┴─────────────────┘

Encuentre la última versión: http://mvnrepository.com/artifact/de.vandermeer/asciitable

Ver también: https://.com/a/39806611/363573



Puedes usar string.format () con el método correcto. El código podría parecerse a esto, supongo

StringBuilder sb=new StringBuilder(); for(int i = 1; i <= numberOfColumns; i++) { sb.append(String.format(%-10s,rsMetaData.getColumnLabel(i); }

A partir de la biblioteca, no creo que haya ninguno que haga el trabajo, ¡sin embargo, podría estar equivocado! realmente investigará sobre esto

También eche un vistazo a este http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html#syntax


use System.out.printf()

Por ejemplo,

String s = //Any string System.out.printf(%10s, s);

imprimirá el contenido de Cadenas, ocupando exactamente 10 caracteres. Entonces, si quiere una tabla, solo asegúrese de que cada celda de la tabla se imprima con la misma longitud. También tenga en cuenta que printf() no imprime una nueva línea, por lo que tendrá que imprimirla usted mismo.


TUIAWT permite usar componentes AWT en una ventana de consola. Sin embargo, no parece que admita List o Table , pero puede brindarle un punto de partida.