Solved

How to open new window on clicking cell of Jtable?

Posted on 2008-06-19
13
367 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

624 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