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 8481507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:34:29+00:00 2026-06-10T19:34:29+00:00

I would like to get the value from the Jtable, and I tried it

  • 0

I would like to get the value from the Jtable, and I tried it using the getvalueat however whenever I try to get the value from the JTable it only get the value from the first column of the selected row, I need to get all the value from the Jtable which I selected. Can you please help me with this one

here is my code:
class GetTableValue implements ActionListener{
    public void actionPerformed(ActionEvent e){
        AbstractButton button = (AbstractButton)e.getSource();
        if(e.getActionCommand().equals(button.getActionCommand)){
            int row = table.getSelectedRow();
            int col = table.getSelectedColumn();

            Object data = (Object)table.getValueAt(row, col);
            JOptionPane.showMessageDialog(null, data);
        }
    }
}

This is my action event where the value of the selected table is shown in the JOptionPane unfortunately it only display one value(which is the one you already selected) not the whole row.

This code is for my Jbutton for call the action event(I already excluded my code from the JTable since it fetch the Jtable value from my database)

ActionListener tableAction = new GetTableValue();


buttonEdit = new JButton("EDIT");


buttonEdit.addActionListener(tableAction);

the code is plain and simple, I also search Mr. G(google) about a good tutorial on fetching row, unfortunately there isn’t a good tutorial for fetching Jtable value(per row).

  • 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-06-10T19:34:30+00:00Added an answer on June 10, 2026 at 7:34 pm

    getValueAt will return you the value of the cell (at row/col). Unless you’re table model supports it, there is no convenient way (beyond what you are doing) to get the whole row in a single request.

    Also, remember, if the table is sorted or filtered, the model indices will not match the view, you need to convert them first, using convertRowIndexToModel and convertColumnIndexToModel

    UPDATE

    The only way around it is if the table model you’re using has a getRow (or equivalent) method. Without know how you are storing the data in the table model it’s next to near impossible to give an accurate answer, but a general idea would be…

    public class MyAwesomeTableModel extends AbstractTableModel {
        // All the usual stuff...
    
        public MyRowData getRowAt(int index) { ... }
    }
    

    Now, MyRowData is what ever implementation of the table data you’ve created. It could be (preferably) a single Object or in the case of the DefaultTableModel an array of objects.

    class GetTableValue implements ActionListener{
        public void actionPerformed(ActionEvent e){
            AbstractButton button = (AbstractButton)e.getSource();
            if(e.getActionCommand().equals(button.getActionCommand)){
    
                int row = table.convertRowIndexToModel(table.getSelectedRow());
                MyAwesomeTableModel model = (MyAwesomeTableModel)table.getModel();
    
                MyRowData data = model.getRowAt(row);
                JOptionPane.showMessageDialog(null, data);
            }
        }
    }
    

    This is all dependent on how you’ve implemented your TableModel and how you’ve implemented your row data, but that’s the general jist

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get the temperature value from Yahoo's weather API. I have
I have JSF code like: <h:inputText id=from value=#{fromToMBean.fromName}/> I would like to get this
I would like to get a dec value from a Hex-encoded string, for examples:
I would like to get from sqlite value that will be different for OS
I am using Rails 3.1.0 and I would like to get a particular value
I would like on gridview update to get a value from a cell in
I would like to know how can I get from database sql a value
I would like to get the value from textbox when I click right-click >
I would like to get returned value from my webservice. I have my class
I would like to get the decimal value from a double value. For example:

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.