Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4072232
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:51:32+00:00 2026-05-20T16:51:32+00:00

I have a JTable . I want to know which row and column are

  • 0

I have a JTable. I want to know which row and column are selected when the user presses Enter. How can I get this information?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:51:33+00:00Added an answer on May 20, 2026 at 4:51 pm

    Add this to your table. Have two int globals for rowClicked and colClicked. Should be good to go

    
            table.addMouseListener(new MouseAdapter(){
                public void mouseReleased(MouseEvent e)
                {
                    rowClicked = rowAtPoint(e.getPoint());
                    colClicked = columnAtPoint(e.getPoint());
                }
    
                public void mouseClicked(MouseEvent e)
                {
                    rowClicked = rowAtPoint(e.getPoint());
                    colClicked = columnAtPoint(e.getPoint());
                }
            });
    
    

    If you talking about using the keyboard to register the event, you must find the selected cell, then add a KeyListener to it. You can use the following code to find the selected cell. Note that it really depends on the cell selection mode.

    
    public void getSelectedCells()
        {
            if (getColumnSelectionAllowed() && ! getRowSelectionAllowed())
            {
                // Column selection is enabled
                // Get the indices of the selected columns
                int[] vColIndices = getSelectedColumns();
            }
            else if (!getColumnSelectionAllowed() && getRowSelectionAllowed())
            {
                // Row selection is enabled
                // Get the indices of the selected rows
                int[] rowIndices = getSelectedRows();
            }
            else if (getCellSelectionEnabled())
            {
                // Individual cell selection is enabled
    
                // In SINGLE_SELECTION mode, the selected cell can be retrieved using
                setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                int rowIndex = getSelectedRow();
                int colIndex = getSelectedColumn();
    
                // In the other modes, the set of selected cells can be retrieved using
                setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
                setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    
                // Get the min and max ranges of selected cells
                int rowIndexStart = getSelectedRow();
                int rowIndexEnd = getSelectionModel().getMaxSelectionIndex();
                int colIndexStart = getSelectedColumn();
                int colIndexEnd = getColumnModel().getSelectionModel().getMaxSelectionIndex();
    
                // Check each cell in the range
                for (int r = rowIndexStart; r &lt = rowIndexEnd; r++)
                {
                    for (int c = colIndexStart; c &lt = colIndexEnd; c++)
                    {
                        if (isCellSelected(r, c))
                        {
                            // cell is selected
                        }
                    }
                }
            }
        }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Jtable with a checkbox in first column. I want to strikethrough
I have been stuck on this problem for a while now. I want to
I have a project with a jTable called AchTable , that is like this:
Can I change column header in Jtable tab from Name to Surname if I
I have a JTable instance, containing a number of rows. The columns in this
I have a JTable which is loaded from a data-structure using table model.The data-structure
I want to implement a properties table in jtable (swing). I want to have
I have a JTable in a GUI and I want to return a number
I have a JTable with some columns. I have a HashMap of the column
I have a JTable where I want to highlight some rows using a custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.