Swing : Table Row Displayer in Dialog

Tables are great for displaying a matrix of information, however they show their limitations when they are showing a lot of columns, or they have columns displaying large amounts of text. For example :

A lot of applications I have come across allow the information displayed horizontally in a row to be displayed vertically in a dialog box. A dialog that pops up can be built custom for each table that you have in your application, but it would be nice if there was something generic.

I have built a generic JTable (TableWithDialog.java) that allows a dialog to pop up when double clicking a row :

Impotant things to note :

  • It is generic in that it will extract the values from all the cells in a table row and display them vertically in a dialog.
  • It uses the cell renderers of each of the table cells to display the values. This means, as in the above example, the cells colour is maintained when being translated across to the dialog, as well as any rendering components. In my example a checkbox.
  • If the textfield is long, it will display the field in a textarea that is three characters high with a scroll pane.

Here is the code :

And here is the test code :

Hope you enjoy, and please leave a comment.


Posted in Swing, Swing Components | Tagged , , , , , , , , | 4 Comments

4 Responses to Swing : Table Row Displayer in Dialog

  1. Adastra says:

    Thank you,
    It was very useful for me, I’m trying to do something similar in my application, so I’ll check this code and test it in my own classes.
    Good work!

  2. Yogesh says:

    Hi,
    Thanks! This is quite useful… Wondering if this can further be enhanced to have UP and DOWN Arrow buttons to scroll the table rows?? Like in case of Event Browser in Windows!
    Thanks for any pointers…

    • felixzacat says:

      So you mean you can scroll up and down the table, and that would automatically update the dialog? You would have to make sure it isn’t a modal dialog, and listen for row selections, which would then jsut update the dialog.

  3. Hari says:

    can anyone tell me? how to show nested JTable data like accordion,
    Thank in advance.

Leave a Reply to Hari Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

THREE_COLUMN_PAGE