Solved

How to open new window on clicking cell of Jtable?

Posted on 2008-06-19
13
338 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

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…
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

746 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

10 Experts available now in Live!

Get 1:1 Help Now