aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTable ->  Custom Cell Renderer -> JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable ->  Custom Cell Renderer -> JTextArea" Watch "JTable ->  Custom Cell Renderer -> JTextArea" New topic
Author

JTable -> Custom Cell Renderer -> JTextArea

Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
Hi Ranchers,

I have a JTable; Need a JTextArea renderer in one of the columns; But TextArea is not completely visible. How to get the scrollbars with in the table cell?

Here's what I'm doing right now:

While constructing table:


I would appreciate any suggestions, work-arounds , code-samples to resolve this issue?

TIA
Ravi
Qunfeng Wang
Ranch Hand

Joined: Jan 28, 2005
Posts: 433
Hi,Ravi.
I'm intrested in your cellrender.Do you use it due to multiline table?Once I implement a cellrender like you.But it looks not very nice in JDK1.4.Can you share your cellrender with me?If anyone can add a scrollbar,that's better.I guess your render just render the TextArea.Maybe you need a render can render scrollbar too.


To be or not to be. It's a question.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
Thanks Craig,

Now scrollPane is visible but I can't do scrollable operations on it. Do I need a mouseListener here? I'm guessing I missing something here... Please let me know if you ever experienced a problem like this.

Ravi
Scott Delap
author
Ranch Hand

Joined: Apr 05, 2005
Posts: 73
Putting a scroll pane type component in a JTable is difficult at best. The reason for this is that JTable doesn't contain components. It creates an image using the renderer for each cell and paints that. There is no component behind each cell. As a result you can't add a mouse listener to your renderer. The JTable uses the renderer to derive the image to use for the cell and then throws it away.

When a cell is clicked and goes into editing mode, the table then creates an actual component based on the corresponding editor that is mapped to it. This component has its bounds/location defined as the area the cell renderer derived image previously occupied.

Relating this to your problem, you could have a cell renderer that uses a JTextArea and editor that uses a JTextArea. However, the first click the user makes won't scroll. It will trigger editing mode. You can hack around this but it isn't pretty.

I would suggest using a JTextfield renderer that displays text as "Text..." or something. When going into editing mode you can have a popup show up that contains your JTextArea.
Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
Thanks Scott,

Neat Idea; TextField with a pop-up JTextArea... I'll work on it and let you know the results

Regards
Ravi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable -> Custom Cell Renderer -> JTextArea