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

Postmark Image

20% off for developers shipping features, not fixing email

Build your product without worrying about email infrastructure. Our reliable delivery, detailed analytics, and developer-friendly API let you focus on shipping features that matter.

Start free

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

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

Okay