Results 1 to 3 of 3
Thread: jtable cell renderer
- 05-21-2009, 06:27 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 22
- Rep Power
- 0
jtable cell renderer
Have a quick question regarding setting my custom cellrenderer to a jtable.
I can set the renderer for a jtable column using the code
Now this works just fine. What i want to ask is can have more that one type of renderer in the same column. I want the cell to have different renderer based on its value (+ve/-ve).Java Code:TableColumnModel cm = table.getColumnModel(); TableColumn tc = cm.getColumn(0); tc.setCellRenderer(new myCustomRenderer());
Also on a side note, is it possible to assign MouseListener to a specific cell in the table ?
Any help would be much appreciated
- 05-21-2009, 10:14 PM #2
You have to change the single renderer so that it treats the cells differently. Likewise, you can have a MouseListener on the table that only does things when specific cells are involved.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-22-2009, 01:08 AM #3
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
For handling MouseEvents on specific cells, use something like
if you need to have extremely different actions for each index, you may want to subclass JTable and add a performIndexAction(int index) method or something like it that calls the action for the specified index, but that could become complicated.Java Code:public void mouseClicked(MouseEvent me){ if(myList.locationToIndex(me.getPoint() == indexToPerformOn){ //Perform action }If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
Similar Threads
-
add a check box to only one cell in a JTable
By aruna1 in forum New To JavaReplies: 4Last Post: 04-03-2009, 06:28 PM -
Color cell in JTable
By ippacciani in forum AWT / SwingReplies: 3Last Post: 03-25-2009, 11:53 AM -
how to use renderer in JTable
By sunilpatel28 in forum Advanced JavaReplies: 0Last Post: 12-09-2008, 08:01 AM -
set different font for each cell in JTable
By success21061985 in forum AWT / SwingReplies: 3Last Post: 09-10-2008, 02:06 PM -
jTable Cell editing
By mahaling_m in forum AWT / SwingReplies: 0Last Post: 06-23-2008, 08:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks