[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

How to open new window on clicking cell of Jtable?

I want to open new window on clicking on the cell of Jtable.
How can I do it using TableCellRenderer
0
inditrozen
Asked:
inditrozen
  • 6
  • 3
  • 3
2 Solutions
 
CEHJCommented:
You can actually just add a MouseListener to the table itself
0
 
CEHJCommented:
If you want to do it via the cell, add a MouseListener to the CellEditor
0
 
inditrozenAuthor Commented:
Hi,

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

Thanks..
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
manuel_mCommented:
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
 
CEHJCommented:
Err.. isn't that what i suggested?
0
 
manuel_mCommented:
Yes, it is. I would recommend that you get the points.
Is that possible?

I just give a simple example for your solution...
0
 
CEHJCommented:
>>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
 
inditrozenAuthor Commented:
Sorry, my mistake...I should have said accept multiple solutions.
Is it possible to correct it?

Thanks..
0
 
CEHJCommented:
OK. Yes, i'll get it reopened. You'll eventually get alerted
0
 
inditrozenAuthor Commented:
Thanks a lot...
0
 
CEHJCommented:
:-)
0
 
manuel_mCommented:
perfect. Thanks.
I hope everybody is satisfied now :-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now