JTable select row by double click, single click

Hi all,
I would like to double click on the row of the JTable and pop up a window for adding stuff, a single click for selecting the row and then in the menu bar I can choose to etither add, change or delete stuff. I try to use the ListSelectionModel but does not seems to distinguish between double or single click.
Any idea, doc, samples?
or I should not use ListselectionModel at all?
thanks
andrew

Hi. I used an inner class. By using MouseAdapter u dont have to implement all methods in the interface..
MouseListener mouseListener = new MouseAdapter()
public void mouseClicked(MouseEvent e)
if(SwingUtilities.isLeftMouseButton(e))// if left mouse button
if (e.getClickCount() == 2) // if doubleclick
//do something
U also need to add mouselistener to the table:
table.addMouseListener(mouseListener);
As I said, this is how I did it.. There are probably alot of ways to solve this, as usual :). Hope it helps

Similar Messages

  • Selecting a page with a single-click instead of double-click

    Is there anyway to make InDesign CS5.5 move my file to the page I have selected in the pages panel without having to double-click the page in the pages panel?
    I keep forgetting that the page selected in the panel may or may not be the page I'm currently editing & this is very frustrating.

    Page that you're currently on is highlighted in reverse (black background white text)
    If you're select a page in the pages panel it highlights blue to indicate it's selected. This allows you to move the page if you need to, or select over dozen other options for that page, numbering, sections, override, move, duplicate, apply master page to, delete, rotate view, colour label, page transiitions, hide master items and spread flattening!
    You double click a page to move to that page. If it was only a single click then it would be quite frustrating to be hopping all over the document when all you want to do is renumber/resection/dupe or over a dozen different options mentioned above.
    CTRL/CMD J will bring up the Go To Page dialog box.
    Navigate with the page numbers as peter suggested.
    There's a reason it works like that - because it works best.

  • JTable, select row on right mouse click

    Hi,
    If I right click on a jTable row in my application, the row I click on does not get selected.
    How can I modify the mouse listener attached to the jtable to deal with this?
    jtable.addMouseListener( { e->
    if (e.isPopupTrigger())
        swing.popupMenu(menuItems).show(e.getComponent(), e.getX(), e.getY());
    } as java.awt.event.MouseListener)Thanks!

    Problem solved!
    jtable.addMouseListener( { e->
    if (e.isPopupTrigger()){
        int row = jtable.rowAtPoint( e.getPoint() );
        jtable.changeSelection( row, 0, false, false );
        swing.popupMenu(menuItems).show(e.getComponent(), e.getX(), e.getY());
    } as java.awt.event.MouseListener)

  • Detect selected row/column in ALV when clicking my button

    Hello,
    I use the cl_salv_table to display my ALV. I have implemented some double click events an so one. But now I like to be able detect u201Cselected  row and coll when I press a button I my Application toolbar.
    How do I get the selected row/column when pressing my button?
    Regards,
    Kenneth

    Give this a try:
    class lcl_disp_code definition.
      public section.
        methods: disp_code
                   for event double_click
                   of cl_gui_alv_grid
                   importing es_row_no
                             e_column.
    endclass.                    "lcl_disp_code DEFINITION
    *       CLASS lcl_disp_code IMPLEMENTATION
    class lcl_disp_code implementation.
      method disp_code.
        perform restrict_data
          using es_row_no-row_id.
      endmethod.                    "on_double_click
    endclass.                    "lcl_disp_code IMPLEMENTATION
    Rob

  • How to reference the selected row on a report by click a radiobox

    I created a report with a column displayed as a radiobox.The report source is like "select htmldb_item.radiogroup(1,.....),rec_id,....from .... where ....",after click one radiobox,i want to get other column's value in the selected row in the after submit process ,can anyone help me?????? how to reference "rec_id" of the selected row?

    Hello,
    First, please tell us your first name, and update your forum handle. It’s make it easier to track your threads, and help you.
    >> apex_application.g_f01(1)" only return the first record's rec_id,if i click radiobox in other rows,it returns the same result as click radiobox in the first row?
    The ‘G_F01’ is an array of values, so apex_application.g_f01(1) will always bring you the first element of this array. If you want to retrieve other values from this array, which will include the values of the radiogroup value of the other lines, you need to use a loop. Something like that should work:
    for i in 1.. apex_application.g_f01.count loop
    … apex_application.g_f01(i) …
    end loop;
    >> after click one radiobox,i want to get other column's value in the selected row in the after submit process
    That means that the value of your radiogroup item should include some indication to the line you are on. If, like in Andy’s example, you can retrieve your record from a table, based on a PK, your radiogroup can return this kind of information. However, if the data on the other columns of the select raw, were just entered/updated by the user (like in a tabular form), the radiogroup item should include information about the row you are in, in order for you to be able to access the corresponding array elements – other G-Fxx arrays – of the other columns in the row. In this case, I believe using checkboxes is preferable.
    Regards,
    Arie.

  • Double Click / Single click problem

    Recently i have been noticing when i single click, using either my magic mouse or trackpad i end up getting a double click, even when my double click is set to as slow as possible.
    Is there anything that can be done to stop this, as this makes many of the menu's in photoshop un usable as well as the dashboard calculator :'(

    My Mother-In-Laws computer (iMac 2GHz- Snow Leopard with current updates) is acting this way also. In her case, she had a Logictec wireless mouse hooked up with the receiver in the keyboard. She has noticed the single click as a double click in Mail and another program (can't remember the other). Suggested that she go back to the original apple mouse and see if it still acted the same way. I'm on the computer now and have been able to recreate the problem with the Apple mouse. Her mouse click setting was all the way to "low". Moved the setting to the middle and didn't see much of a difference. Maybe slightly more instances of double-clicks.
    I have two other macs(my Mac Pro and another iMac) I use on a regular basis and have not seen this problem. But they are also behind on Snow Leopard OS updates. I'm guessing this is an internal problem Apple will have to fix.

  • Simple JTable / Select Row example?

    Hi - I'm having a really hard time wrapping my brain around JTables and their events. Can anybody give me just a real simple example of how to get the value of whatever cell (row, preferrably) by clicking on that cell / row?

    Hey there,
    im currently doing Jtables within a system i am coding too so thought i would help ya out!
    1. You can recognise if a row is selected within your table by using a possible two methods: example of how this can be implemented:
    //This method used for only one row at a time being selected
    int selectedRow = table.getSelectedRow(); (table being the name of your JTable obviously)
                        if (selectedRow == -1) {//When there is no selected row show error message
                             JOptionPane.showMessageDialog(null, "Must select an employee from the table", "Error Message",
                                                      JOptionPane.ERROR_MESSAGE);
                        else {
                        //DO SOMETHING                    }
                   }2. Or you could use the public int [ ] getSelectedRows() method of recognising selected JTable rows: example of how u might implement this, this returns an array of interger values when 1 or more rows are selected:
    int [ ] rowselected = table.getSelectedRows();
    //In order to go through each selected row and do something with it a loop is obviously needed like:
    for (int i = 0; i < rowselected.length; i++) {
                        String empName = (String)(table.getValueAt(rowselected,0));
                        System.out.println(empName);
    Hope this helps ;-)

  • JTable: Selecting rows in columns independently

    Dear all,
    I have a JTable with two columns. I want the user to be able to select cells in columns independently. At present, the entire row gets marked as selected. Is it possible at all to, for instance, select row1 1 to 3 in column 1 and rows 4 to 5 in column 2? If so, where's the switch? Thanks a lot in advance!
    Cheers,
    Martin

    Are you trying to use a seperate table for each column.
    Thats not a good idear.
    Here is what you have to do.
    1. Create a sub class of JTable
    2. You will have to redefine how the selection is done so. You will need some sort of a collection to store the list of selected cells indexes
    2.1 Selecting a cell is simply adding the coordinations of the cell to the selection
    2.2 de selecting is just removing it from the collection.
    2.3 Here is what you have to override
         setColumnSelectionInterval()
         setColumnSelectionInterval()
         changeSelection()
         selectAll()
         getSelectedColumns()
         getSelectedColumn()
         getSelectedRows()
         getSelectedRow() You migh also need few new methods such as
         setCellSelected(int row, int column, boolean selected);
         boolean isCellSelected(int row, int column);
         clearSelection();
         int[][] getSelectedCells();You will have to implement the above in terms of your new data structure.
    3. Handle mouse events.
    Ex:- when user cicks on a cell if it is already selected it should be deselected (see 2.2)
    other wise current selected should be cleared and the clicked cell should be selected
    if your has pressed CTRL key while clicking the the cell should be selected without deselecting the old selection.
    ---you can use above using a MouseListener
    When the user hold down a button and move the mouse accross multiple cell those need to be selected.
    --- You will need a MouseMotionListener for this
    You might also need to allow selection using key bord. You can do that using a KeyListener
    4. Displaying the selection
    You have to make sure only the selected cells are high lighted on the table.
    You can do this using a simple trick.
    (Just override getCellEditor(int row, int column) and getCellRenderer(int row, int column) )
    Here is what you should do in getCellRenderer(int row, int column)
    public TableCellRenderer getCellRenderer(int row, int column)
      TableCellRenderer realRenderer = super.getCellRenderer(int row, int);
      return new WrapperRenderer(realRenderer,selectedCellsCollection.isCellSelected(row,column));
    static class WrapperRenderer implements TableCellRenderer{
        TableCellRenderer realRenderer;
        boolean selected;
        public WrapperRenderer(TableCellRenderer realRenderer, boolean selected){
           this.realRenderer = realRenderer;
           this.selected = selected;
        public Component getTableCellRendererComponent(JTable table,
                                                   Object value,
                                                   boolean isSelected,
                                                   boolean hasFocus,
                                                   int row,
                                                   int column){       
            return realRenderer.getTableCellRendererComponent(table,value,selected,hasFocus,row,column);
    }What the above code does is it simply created wrapper for the Renderer and when generating the rendering component it replaces the isSeleted flag with our on selected flag
    and the original renderer taken from the super class will do the rest.
    You will have to do the same with the TableCellEditor.
    By the way dont use above code as it is becouse the getCellRenderer method create a new instance of WrapperRenderer every time.
    If the table has 10000 cells above will create 10000 instances. So you should refine above code.
    5. Finnaly.
    Every time the selection is changes you should make the table rerender the respective cells in or der to make the changes visible.
    I'll leave that part for you to figure out.
    A Final word
    When implementing th above make sure that you do it in the java way of doing it.
    For the collection of selected cells write following classes
    TableCellSelectionModel  // and interface which define what it does
    DefaultTableCellSelectionModel //Your own implementation of above interface the table you create should use thisby default
    //To communicate the selection changes
    TableCellSelectionModelListener
    TableCellSelectionModelEventif you read the javadoc about similer classes in ListSelectionModel you will get an idear
    But dont make it as complex as ListSelectionModel try to keep the number of methods less than 5.
    If you want to make it completly genaric you will have to resolve some issues such as handling changes to the table model.
    Ex:- Rows and colums can be added and removed in the TableModle at the run time as a result the row and column indexes of some cells might change
    and the TableCellSelectionModel should be updated with those changes.
    Even though the todo list is quite long if you plan your implementation properly the code will not be that long.
    And more importantly you will learn lots more by trying to implementing this.
    Happy Coding :)

  • Photoshop CC Toolbar buttons sticking.. getting stuck on single click

    Toolbar buttons get stuck in dropdown menu with single click... it's extremely irritating especially being in photoshop all day. I have to click the intended tool button twice in order to get rid of the drop down menu options. I realize it should do this when I double click or hold down click.. but not when I simply want to select a tool with a single click.  I've tried everything. Please help!

    Try resetting the tools:
    Also try changing the mouse settings such as double click speed..
    Benjamin

  • Overriding the SelectionForegroundColor of a selected row in a JTable

    Hi
    First, apologize for my poor English.
    I looked for a similar topic in the forum, but coudn't find one.
    What I want to achieve is this :
    upon data contained in a column, I want the foreground color of the row to be gray. To do this, I write my own TableCellRenderer and it works perfectly except for the unique selected row of the table (single selection model) whose foreground color is the table's selectionForegroundColor.
    I found a workaround...but the code is awful and leads to OutOfMemoryErrors.
    Here is the code :
    <
    public Component getTableCellRendererComponent(JTable table,
    Object value,
    boolean isSelected,
    boolean hasFocus,
    int row,
    int column) {
         boolean isGrayColored = false;
         // some process to set whether the foreground color should be gray
         if (isGrayColored) {
              //table.setSelectionForeground(Color.gray);
              setForeground(Color.gray);
         } else {
              //table.setSelectionForeground(Color.black);
              setForeground((isSelected) ? table.getSelectionForeground() : table.getForeground());
         if (table != null && value == null && isSelected && hasFocus) {
              return this;
         } else {
              return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    >
    If I uncomment the lines "table.setSelectionForeground(..", I got the expected result.
    Thanks for your help
    Regards,

    Try this:
          public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
             if (isSelected && hasFocus) {
                setForeground(Color.black);
             } else {
                setForeground(Color.gray);
             setText((value==null)?"":""+value);
             return this;
          };o)
    V.V.
    PS: If it helps, don't forget the dukes!

  • OHJ - Displaying topics on a single click

    I am using OHJ 4.2.7 version. In my application under the Contents tab, I would like to display the topic when a user clicks(Single click) on a particular TOC item.
    Currently the topic is getting displayed only if the user double clicks on an item. any ideas?

    Hey, did you ever get any insight on this issue?

  • Windows 7 classic shell without single click??

    I have 700 windows xp machines in a retail environment that I am prepping to swap out with Windows 7 machines.  These xp machines are joined to our domain, and fairly locked down via group policy.  I am in the process of putting together our new
    Windows 7 image and building the group policies.  Our goal is to maintain as much of the same look and feel that we have with our Win XP machines for this application.
    That being said - I have enabled Windows Classic theme (by leaving UserConfiguration > Administrative Templates > Control Panel > Personalization > Force a specific visual style or force Windows Classic blank).  This seems to work just fine.
     I have the expected results for background, start menu, window appearance.  What is confusing me is - my mouse somehow got set to single click.  I do not want this.  It seems to have happened with turning on windows classic??  I haven't
    been able to find a GPO or GPP (or registry hack, for that matter) to turn it off.
    I look in Explorer > Folder and search options > Click items as follows - Double-click to open an item is the radio button that is marked active.  I was able to set my staging user (non admin level) to a local admin, re-login, click Single click
    to open an item --> click apply --> click double click to open an item --> click apply and ok.  Now things are as I want them.  It seems that by manually making this change it does the trick.  I won't have this luxury in the field.
    Any input as to a workaround or what is actually going on would be greatly appreciated.
    Thanks
    sb

    Hi,
    To disable the "single click", you need to disable the GPO setting "Turn on Classic Shell" under the node given below,
    User Configuration\Policies\Administrative Templates\Windows Components\Windows Explorer\Turn on Classic Shell
    Regards,
    Gopi
    JiJi
    Technologies

  • How do I set only the first row of a DataGrid as the selected row?

    I have a "Go" button on a search form that fetches data into an already data bound grid.  After the data is fetched, I want to make the first row in the Datagrid the selected row, as if the user clicked on it.  If the result set is empty, I don't want the code to crash.  (I only want one row to be able to be selected at a time)
                protected function btnGo_clickHandler(event:MouseEvent):void
                    getSBJsResult.token = baa_data_svc.getSBJs(cmbSrch.text);
                    grdSBJs. //  ?????  What goes here to select the first row?

    This should do it.
    If this post answered your question or helped, please mark it as such.
    if(myDataGrid.dataProvider.length > 0){
      myDataGrid.selectedIndex = 0;

  • Listen double clicks on JTable's row

    hi,
    I want to know how to catch double clicks did on a specific JTable's row, or any cell on that.
    I know that's possible because JTable is a JComponent..so, I want to know how to catch the event when the user press Enter over a single selected row, too...
    If you may show me and example or specific links, I'll thank you so much..
    lucky..

    b) The Enter key is used to move the row selection to
    the next row so you need to override the default
    mappings of the table.
    This posting shows how you would do the above on a
    JList. The code should be similiar for a JTable.
    http://forum.java.sun.com/thread.jspa?forumID=57&threa
    dID=626866Thanks anyway...I fix that with a tricky and simplest solution.
    I only put a KeyEventListener on the table and catch the keyEvent, and if it's a EnterKey, then check wich row is selected on table.
    table.addkeyListener(new KeyListener(){
                public void keyPressed(KeyEvent e) {
                    if(e.getKeyCode()==KeyEvent.VK_ENTER){
                        int[] selected_rows = table.getSelectedRows();
                        if(selected_rows.length==1){
                            int row = selected_rows[0];
                            DefaultTableModel table_model = (DefaultTableModel)table.getModel();
                            Object element_at_row = directory_model.getValueAt(row, 1); //I wanna Only the element at column 1
                             //do more things...                      
    //....other interface's methods..
    );

  • JComboBox in JTable to activate when double-click instead of single-click

    I like to know if it is possible to change the default behaviour of JComboBox within the JTable,
    such that instead of single click on the JTable cell for the combo box's popup to appear, I double click on it instead.
    If it is possible please give some advice.
    Thanks.

    I couldn't get to settings because I couldn't scroll and don't know where that is located. I just saw a similar question from someone else. Three clicks on home button worked to turn off voiceover !! Phew!

Maybe you are looking for

  • Short dump

    Hi forum, Pls help me out...I'm getting short dump if i execute this.. pls correct the code....... REPORT  ZPAY_REG NO STANDARD PAGE HEADING line-size 150 line-count 65(3). TYPE-POOLS: slis. TABLES:    payr,    t012,    t012k,    t51r5. Data : begin

  • Mac Pro no longer connects to network via ethernet.

    Since coing back from Thanksgiving break and my Mac Pro 1,1 will no longer connect to my router through via ethernet.  This means I can neither connect to internet nor connect to devices like my laptop and Apple TV.  Strangely, I can still connect to

  • Encoding Issue : JMS and Mapping : utf-8 iso8859-1

    Hi All, I am facing some problem with encoding issue. Scenario :  JMS -->  SAP PI --> JMS Requirment : Input plain text file contain some special characters,"©®" . Based on this condition,In Java Mapping                    we check the Payload and ch

  • Why the new version of itunes for windows is falling to install properly , am I the only one with this problem?

    how to fix it?, i already try to install an older version, also uninstalled the whole thing and reinstalled it with no luck, and always at mid installation an error message appears saying: I don't know what to do, not an expert at all on this things.

  • Shooting Bullets

    Ok well I just started scripting little games in flash about a month ago and now i feel like trying to create my own game instead of constantly following tutorials. I'm trying to create a game sort of like space shooter and i am only doing this just