Results 1 to 4 of 4
  1. #1
    Otyugh is offline Member
    Join Date
    Dec 2012
    Posts
    7
    Rep Power
    0

    Default JTable, put a listener in the rows !

    Hey,
    i'm stuck.
    I want to make a JTable containing a column of Icones.

    I made a AbstractTableModel containing the Path of the icones to set, and then with DefaultTableCellRenderer i made "setIcon(path)".

    This worked good.


    Now i have this JTable containing a column of Icones, and i want to "change them" on a double-click.
    I just lost hours to fail again and again.
    I just don't know where i must put theses listeners and how ! When i put them on "DefaultTableCellRenderer" this makes nothing, and i can't put listeners on the Icon because they are not components !

  2. #2
    Otyugh is offline Member
    Join Date
    Dec 2012
    Posts
    7
    Rep Power
    0

    Default Re: JTable, put a listener in the rows !

    More simple, a MouseListeners in a JTable, is that even possible by a "clean" way ? I mean, i found some tutorials, but only by dirty ways.

  3. #3
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default Re: JTable, put a listener in the rows !

    Quote Originally Posted by Otyugh View Post
    Now i have this JTable containing a column of Icones, and i want to "change them" on a double-click.
    I just lost hours to fail again and again.
    Hi Otyugh, I'm not sure that I understand what you want to accomplish. Do you want to be able to double click a cell containing an icon, and have an action performed?

    If so, you could easily accomplish this with a MouseListener, just as you yourself proposed.

    I guess it would look something like this:

    Java Code:
    		table.addMouseListener(new MouseAdapter(){
    			public void mouseClicked(MouseEvent e){
    				if (e.getClickCount() == 2){
    					//TODO What you want to happen!
    				}
    			}
    		});
    And to get it to work on the cell you click:


    Java Code:
    table.addMouseListener(new MouseAdapter(){
        public void mouseClicked(MouseEvent e){
            if (e.getClickCount() == 2){
                //TODO What you want to happen!
    			JTable target = (JTable)e.getSource();
    			int row = target.getSelectedRow();
    			int column = target.getSelectedColumn();
            }
        }
    });
    I hope this helps!

    Happy new year,
    Z

  4. #4
    Otyugh is offline Member
    Join Date
    Dec 2012
    Posts
    7
    Rep Power
    0

    Default Re: JTable, put a listener in the rows !

    May my stupidity be apologized, and may your help be thanked !

Similar Threads

  1. Replies: 2
    Last Post: 11-09-2011, 06:24 PM
  2. listener for a jtable triggers twice
    By kulangotski in forum AWT / Swing
    Replies: 2
    Last Post: 01-16-2011, 01:08 AM
  3. Urgent:Jtable and key Listener
    By simmi in forum AWT / Swing
    Replies: 3
    Last Post: 02-02-2010, 05:56 AM
  4. JTable Cell Focus Listener
    By Manfizy in forum New To Java
    Replies: 1
    Last Post: 07-21-2009, 08:08 AM
  5. add an undo listener to a Jtable
    By christina in forum Advanced Java
    Replies: 12
    Last Post: 01-29-2009, 07:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •