Solved

How to open new window on clicking cell of Jtable?

Posted on 2008-06-19
13
345 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This video teaches viewers about errors in exception handling.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now