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

can anyone help me with this , I have a jtable and I want
I have a JTable which I want to have left-click and right-click JPopupMenu on
I have a JTable on which Components can be dropped. Some of those components
I have a JTable of data. I want it so that when a row
i have jtable with 2 column then i want to insert value of it
I have a Jtable and I want to highlight a row by adding a
I have a JTable and i want a cell (or its row) painted in
I have A jtable. (tablesummary). one of it's column is EXPIRY. i want to
I have a JTable where a user can create a custom report. They can
I have a problem regarding my JTable, I don't know how can I store

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.