Solved

How to open new window on clicking cell of Jtable?

Posted on 2008-06-19
13
363 Views
Last Modified: 2013-11-23
I want to open new window on clicking on the cell of Jtable.
How can I do it using TableCellRenderer
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
  • 6
  • 3
  • 3
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 21820651
You can actually just add a MouseListener to the table itself
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 21820675
If you want to do it via the cell, add a MouseListener to the CellEditor
0
 

Author Comment

by:inditrozen
ID: 21820689
Hi,

Can  you please suggest some sample code snippet for adding  MouseListner to Jtable, that will be very helpful to me

Thanks..
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 6

Assisted Solution

by:manuel_m
manuel_m earned 250 total points
ID: 21820803
For example...
DefaultTableModel model = new DefaultTableModel(new String[] { "column1", "column2" }, 1);
final JTable table = new JTable(model);
table.addMouseListener(new MouseListener() {
 
    public void mouseClicked(MouseEvent e) {
        if (table.getSelectedColumn() == 0 && table.getSelectedRow() == 0) {
            // open new window...
            System.out.println("openening new window");
        }
    }
 
    public void mousePressed(MouseEvent e) {
    }
 
    public void mouseReleased(MouseEvent e) {
    }
 
    public void mouseEntered(MouseEvent e) {
    }
 
    public void mouseExited(MouseEvent e) {
    }
});
 
// Or do it with the MouseAdapter...
 
DefaultTableModel model = new DefaultTableModel(new String[] { "column1", "column2" }, 1);
final JTable table = new JTable(model);
table.addMouseListener(new MouseAdapter() {
 
    @Override
    public void mouseClicked(MouseEvent e) {
        if (table.getSelectedColumn() == 0 && table.getSelectedRow() == 0) {
            // open new window...
            System.out.println("openening new window");
        }
    }
});

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21820871
Err.. isn't that what i suggested?
0
 
LVL 6

Expert Comment

by:manuel_m
ID: 21820927
Yes, it is. I would recommend that you get the points.
Is that possible?

I just give a simple example for your solution...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21820984
>>Yes, it is. I would recommend that you get the points.

That's OK manuel_m, your contribution is valuable and shouldn't be ingored. Neither should mine
0
 

Author Comment

by:inditrozen
ID: 21820991
Sorry, my mistake...I should have said accept multiple solutions.
Is it possible to correct it?

Thanks..
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21821030
OK. Yes, i'll get it reopened. You'll eventually get alerted
0
 

Author Closing Comment

by:inditrozen
ID: 31468698
Thanks a lot...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21821376
:-)
0
 
LVL 6

Expert Comment

by:manuel_m
ID: 21821785
perfect. Thanks.
I hope everybody is satisfied now :-)
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

751 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