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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

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

AWS GenAI Live!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️