?
Solved

How to add  MouseListener to Icon in JTable cell?

Posted on 2008-06-26
3
Medium Priority
?
2,914 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses

752 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