When creating a JTable, a JScrollPane accompanies it in many cases. However, there may be times where you do not want the JTable added to the JScrollPane.

The problem I encountered was finding out the JTableHeader could not be seen. I am not sure if there is a solution to this but what I did was to get a reference to the JTableHeader and add it as another component on top of the JTable.

Add both the JTable and JTableHeader in a container like JPanel and set its layout to BorderLayout. See example.

That should make it display those table headers.

If you encounter this problem, it is most likely that your JTextArea is placed within a JScrollPanel. When the cell editor gets called, the focus is received by the scrolling panel instead of your text area.

To fix this problem, you can add a MouseListener in your JTable and call the editCellAt() method as well as having a getter method in your cell editor class and calling the requestFocusInWindow() method.

That should fix the problem.

Sample code below.

Related Posts Plugin for WordPress, Blogger...