JTable



2
When working with tables, it may be useful to detect selection changes. If for example, you need to sum the values of a specified column in a selection range, this method will be most essential. If you explore the available methods to add listeners to a JTable, you will notice there’s no such thing as a selectionListener. This is because the JTable has its own selection model, where you can add the listener. The following code illustrates the way to go to add a selection listener: [crayon-59ebb7a59e9e5427118660/]

JTable, detecting selection changes // ListSelectionListener /*Selection Changed ...


JTable inside JTable cell 11
Java is one of the greatest object oriented languages. This can easily be seen when using swing components. JTables are a great example. Briefly, jTables are just a base to display a matrix of JComponents. So inside a JTable you can embed any object which extends the JComponent class. Today I’ll show you an easy way to display a JTable inside another jTable as a cellRenderer. If you’ve ever worked with multivalued data models this can be of great help. In this simple example I’ll create a small contact manager where the name, phones, and e-mail addresses of the contact […]

Displaying a jTable inside another jTable // JTable cellRenderer



5
When you press the Enter key while in a JTable, you’ll notice how the row selection changes to the next row or to the first row if the former row selected was the last row in the model. You can change this playing with the traversal key policy, but this is quite complicated. The easy way is to consume the event if the enter key has been pressed. You can accomplish this doing the following: [crayon-59ebb7a59f17e783257437/] It’s very important to consume the event during the keyPressed event and not during the other possible keyEvents not doing so will mean that […]

Remove JTable’s Enter Key behavior


JTable Alternate Row Color 7
Java tables are great but complex. The good thing about them is that you can do with them whatever you want. Even more, the view is completely separated from the model so you can even play more. JTables in brief (bad thing) are just a bunch of components put together. So anything you can de to a Component you can do in a JTable. To make a JTable render each row in a different color, you just have to extend the JTable’s prepareRender method. [crayon-59ebb7a59f3d9480464150/] The above code simply gets the component that was going to be rendered and changes […]

JTable Alternate Row Background