Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swing JTable customization for filtering/searching

I'd like to add filtering/searching capability for all columns (so that it is generic) the logic is not a problem. However, I was thinking is that the best way to do that in terms of visualization is having a text field above each column header (or part of the column header)?

I've run into a couple of problems when trying to achieve that:

  1. Embedding within the column header demands implementing a new renderer + there's the problem that somehow I need to catch the event because the cell is drawn and does not respond to events. Looks like an overkill to me.
  2. Having a separate line (panel) of text field components above each column sounds much easier at first glance, however, aligning the text field with the columns is problematic since I didn't find an API in JTable or TableColumn that returns the coordinates of the column. Moreover, moving the column around would mean adjusting the text fields as well (which is possible but another overhead).

Am I missing something or it is indeed that hard to achieve something as simple as that? Any other suggestions?

like image 763
GBa Avatar asked Dec 07 '25 21:12

GBa


1 Answers

There is a library for your first approach. It can easily be integrated and works really great: Swing Bits

like image 196
Kai Avatar answered Dec 10 '25 09:12

Kai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!