[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to add  MouseListener to Icon in JTable cell?

Posted on 2008-06-26
3
Medium Priority
?
2,917 Views
Last Modified: 2013-12-14
Hi Experts,
In my JTable , I am using custom cellRenderer to add the  icon depending upon value of cell.
Table cell shows icon followed by text, I need to open new JMessageDialog when user clicks this icon .

How I can add  mouselistner to this icon ?

public class DescriptionCellRenderer extends DefaultTableCellRenderer {
 
	
	 public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected, boolean hasFocus, int row, int column) {
 Component cell = super.getTableCellRendererComponent(table, value,isSelected, hasFocus, row, column);
		
		String val=value.toString();
		
		if (!val.equals("ok")){
							ImageIcon icon = new ImageIcon("help.gif");
			setText(val);
			setIcon(icon);
 
		}		
		return cell;
	 
	    }
 
	}

Open in new window

0
Comment
Question by:inditrozen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 92

Expert Comment

by:objects
ID: 21879871
you don't, you add your listener to the table. Then calculate which cell was clicked using rowAtPoint(), and columnAtPoint()


0
 

Author Comment

by:inditrozen
ID: 21882920

I added listner to table , and now when I click on the cell new dialog will open.
Now this cell contains icon followed by text. And my requirement is ,when  user clicks on icon then only dialog message should open.and when he clicks on text ,nothing should happen.
How can listener identify difference between icon and text.?
Is it possible to get the cell value at perticular position?

Thanks in advance
0
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 21888249
yes, use the getValueAt() method of the table/model

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question