Hide JTable Column Headers
Posted by tech on
March 1, 2010
|
|
Hiding all column headers of a JTable is pretty easy. You just need to set to null the method setTableHeader(null).
A very common problem is that once you call this method, nothing happens. The column headers still get displayed. While other workarounds involve setting column header labels to blank, you would still need column names to get access to the column object through their column names (I prefer this way compared to accessing it via a column’s index number directly).
The JTable method setTableHeader() when set to null is only good if there is no JScrollPane on it. Chances are there is one attached to your JTable object because it is needed when you have many rows to consider. You need to call a second method from the JScrollPane in order for the column headers to be hidden. Call the setColumnHeaderView() method and set it to null.
That should do the trick.
Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.tags: column, header, hide, jtable
2 Comments
Hide Unhide Nodes Of JTree
Posted by tech on
October 26, 2009
|
|
I have read a number of articles that featured source codes from forums and sites on how to show or hide nodes of a JTree. The easiest code that I found that was easy to understand and use are source files labeled InvisibleNode.java and InvisibleTreeModel.java.
You can easily search that in Google to get those files. The result that I wanted to accomplish was to show only 2 checkbox leaf nodes at most if the last leaf node of the parent node has a button labeled HIDE and is clicked. I know it is hard to visualize so I included a snapshot of my JTree.
My JTree‘s parent nodes contain leaf nodes that have checkboxes and a button at the end of each parent node if there consists more than 2 checkbox leaf nodes per parent node. By default the button is labeled HIDE. If I click on it, it will show only 2 checkboxes while hiding the rest (except the button) and the button’s label will change to SHOW. If I click on the button again, it will all all sibling leaf nodes.
Those two Java source files easily did the trick in hiding and showing tree nodes.
Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.








