DEV Community

Edgar Rios Navarro
Edgar Rios Navarro

Posted on

JTable Color Header

A diferencia de las aplicaciones web, personalizar grillas (tablas) en Java Swing requiere de mucho más código. Pero podemos ayudarnos con clases utilitarias.


1) Original

Consideremos este ejemplo:

Image description

2) Column Group

Para agregar la capacidad de agrupar columnas, emplearemos una clase llamada ColumnGroup. Reconoce el título y las columnas que debe agrupar.

ColumnGroup columnGroup = null;

int[] columns = {8,9};
columnGroup = new ColumnGroup("Precio Venta " + "S/.", columns);

UtilityTable.initSelectList(jTable, tableModel, ConstantsVentas.columnsList, 
columnGroup );
Enter fullscreen mode Exit fullscreen mode

Image description

3) Color Header

También podemos cambiar el color de columnas específicas. Ello lo conseguimos indicando en la clase FarmaColumnData, el color de fondo.

Image description

Image description


Documentación

https://docs.oracle.com/javase/tutorial/uiswing/components/table.html
https://github.com/edgargs/table-color-header.git

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay