• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JTable Cell Renderers

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I am currently trying to use a JTextPane as a cell renderers for a JTable but it does not seem to work although the program compiles. I alsways get an error stating class cast exception saying that i must cast the editor component to JTextField instead of a JTextPane although i am using a JTextPane as a cell renderer.

This exeption gets thrown when i try to apply some font to the selected text in the JTextPane.

Below is a small compilable that i have done which compiles and throws the exception that i have mentioned about

Here is the compilable example



Why this exception is occurring i am not very sure and really hope someone can help me with this problem.

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you setting the editor component ?? I see that you are only setting a JTextPane as the Cell Renderer and not the Cell Editor. Both are different.
 
Richard West
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

Originally posted by Sam Codean:
Where are you setting the editor component ?? I see that you are only setting a JTextPane as the Cell Renderer and not the Cell Editor. Both are different.



I tried writing and using the below code by extending the DefaultCellEditor class and uisng it but it only got worse as now if i apply the font to the selected text in the cell all the text dissapears

Here is the code of the class theat extends the default cell editor class



Here is the entire code using the above class which compiles



Why the JTable is reacting in this way i am not sure and hope someone can
point out to me why this is happening.

Thank You

Yours Sincerely

Richard West
[ November 21, 2006: Message edited by: Richard West ]
 
Richard West
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

Anyone at all?

Richard West
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Richard West:
I tried writing and using the below code by extending the DefaultCellEditor class and uisng it but it only got worse as now if i apply the font to the selected text in the cell all the text dissapears

Here is the code of the class theat extends the default cell editor class




Well of course the text disappears, since the JTextPane you
return in your getTableCellEditorComponent() has never had
any text added to it.

You can try something like textPane1.setText((String)value).
Or since you are keeping a reference to the Document you
could do something with dse.replace() instead, though I'm
not sure why you need the 'dse' field. I'm also not sure
why you are messing with StyledEditorKits.

I would also recommend that you change the textPane1 and
styleEditorKit1 fields to not begin with capital letters,
though that makes no real difference.
 
Richard West
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I decided to revamp the entire cell editor and the new editor looks like the below



There now still seems to be a little problem.

You see now font can be applied to the cell in a particular sentence when the cell is selected but when the cell is deselected the font all dissapears

Also once i have have applied font to the selected text in the and deselected the cell the font all dissapears as mentioned earlier but also when i edit the same cell again the font is also all dissapears.

Why is it reacting in this way?
Am i missing something?

Will it make a difference if a renderer that is appropriate for this use is written?

If yes how does one go about writing this renderer?

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Head over to:
http://wordhoard.northwestern.edu/userman/javadoc/edu/northwestern/at/utils/swing/XTextPaneTableCellRenderer.html

It's under GNU General Public License and seems to run very well.
 
Richard West
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

Originally posted by Peter Taucher:
Head over to:
http://wordhoard.northwestern.edu/userman/javadoc/edu/northwestern/at/utils/swing/XTextPaneTableCellRenderer.html

It's under GNU General Public License and seems to run very well.



The link you showed me leads to a javadoc and does not seem to lead to any examples or code.

Do have the link to where this TextPane renderer code or example resides at?

Richard West
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You coul've come up with this very simple (just go to the homepage where the javadoc is hosted):
http://wordhoard.northwestern.edu/userman/dev-files.html
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DefaultCellEditor is a convenience class for three very specific components. You are using
a different component so this class will not work. When you super(new JTextField()) in the
constructor, the editor will use a JTextField. It will not understand anything about
JTextPane.
When doing custom rendering and editing the renderer and editor must be matching
components, ie, built the same.
The table is a drawing, a graphic snapshot made by configuring the renderer, translating
it to the (row, column) location and having it draw itself. The table and its model have
only the [Object value] to use to give to the renderer for the rendering. There is no
provision made to store these attribute–value pairs in this object. Using this
[Object value] is the only way we have of saving, and transferring information to be used
to make the table.
So it would make sense to create a class that can store the information you want to render
in your table, both text and attributes for the StyledDocument. There are many ways to put
these things together.
Here's a minimal modification of your app to help you get started:
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic