Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2005

Tip: Looking for answers? Try searching our database.

Need help with a viewToModel() problem in a JTable

Thread view: 
Gerald Rosenberg - 29 Jun 2005 08:39 GMT
I have a JTable with a column that is rendered using a JTextPane-based  
cell-renderer.

On a single click on that column in the JTable, I would like to
determine the text offset of the click in the row under the user click.

I thought the code below would work, but the viewToModel() method fails
since the renderer is not actually visible -- internal to the
viewToModel() method, the rectangle that contains the rootView is null,
which causes the method to return -1.

Can't see a workable way of forcing a visible renderer on a mouse click.  
Am I missing something or is there an alternate/better way of doing
this?

Thanks,
Gerald

public void mouseReleased(MouseEvent e) {
   Point ept = e.getPoint();
   int row = table.rowAtPoint(ept);
   int col = table.columnAtPoint(ept);

   Rectangle r = table.getCellRect(row, col, false);
   Point local_offset = new Point(ept.x - r.x, ept.y - r.y);
   JTextPaneRenderer jtpr = (JTextPaneRenderer) table.getCellRenderer
(row, col);

   int mouseClickOffset = jtpr.viewToModel(local_offset);
}
Christian Kaufhold - 29 Jun 2005 12:50 GMT
> I have a JTable with a column that is rendered using a JTextPane-based  
> cell-renderer.
[quoted text clipped - 10 lines]
> Am I missing something or is there an alternate/better way of doing
> this?

Use a TableCellEditor.

Christian
Gerald Rosenberg - 29 Jun 2005 15:17 GMT
> > I have a JTable with a column that is rendered using a JTextPane-based  
> > cell-renderer.
[quoted text clipped - 12 lines]
>
> Use a TableCellEditor.

Thanks, but could you explain your suggestion.
Christian Kaufhold - 30 Jun 2005 15:55 GMT
>> > I have a JTable with a column that is rendered using a JTextPane-based  
>> > cell-renderer.
[quoted text clipped - 14 lines]
>
> Thanks, but could you explain your suggestion.

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender

Christian


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.