Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable -> Custom Cell Renderer -> JTextArea

 
Ravi Sathish
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ravi Sathish
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Scott,

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

Regards
Ravi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic