?
Solved

How to open new window on clicking cell of Jtable?

Posted on 2008-06-19
13
Medium Priority
?
371 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 1000 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
Technology Partners: 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!

 
LVL 6

Assisted Solution

by:manuel_m
manuel_m earned 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

718 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