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

  • Home
  • SEARCH
  • 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 6087655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:53:42+00:00 2026-05-23T11:53:42+00:00

I have a JTable with a custom Abstract Table Model and I would like

  • 0

I have a JTable with a custom Abstract Table Model and I would like to select a row in my table and that information to appear in the textboxes to the left. I would like this to happen automatically with out the use use of any buttons. The only approach I can think of involves a button. My table model looks like this:

public class AdminTableModel extends AbstractTableModel {
private ArrayList<Contestant> contestants;
private String[] columns={"First Name", "Last Name", "Entry"};

public AdminTableModel(ArrayList<Contestant> contestants) {
    this.contestants = contestants;
}

public AdminTableModel(List l) {
    contestants.addAll(l);
}

public int getRowCount() {
    return contestants.size();
}

public int getColumnCount() {
    return columns.length;
}

public String getColumnName(int col) {
    return columns[col];
}

public Object getValueAt(int row, int col) {
    Contestant contestant = contestants.get(row);
    switch(col){
        case 0:
            return contestant.getFirst_name();
        case 1:
            return contestant.getLast_name();
        case 2:
            return contestant.getEntry();
        default:
            return null;
    }
}

}

With the code for my table looking like this:

public class ContestantsTable extends JTable{

public ContestantsTable(ArrayList<Contestant> contestants) {

    AdminTableModel atModel = new AdminTableModel(contestants);
    this.setModel(atModel);
    atModel.fireTableDataChanged();
}

}

Here is the panel with the text fields that I want to refresh:

public class ContestantAddPanel extends JPanel {
private JLabel jlFirst_name;
private JLabel jlLast_name;
private JLabel jlEntry;

private JTextField jtfFirst_name;
private JTextField jtfLast_name;
private JTextField jtfEntry;

public ContestantAddPanel() {
    jlFirst_name = new JLabel("First Name: ");
    jlLast_name = new JLabel("Last Name: ");
    jlEntry = new JLabel("Entry: ");

    jtfFirst_name = new JTextField();
    jtfLast_name = new JTextField();
    jtfEntry = new JTextField();

    this.setLayout(new GridLayout(3,2));

    this.add(jlFirst_name);
    this.add(jtfFirst_name);
    this.add(jlLast_name);
    this.add(jtfLast_name);
    this.add(jlEntry);
    this.add(jtfEntry);
}

public String getFirstName(){
    return jtfFirst_name.getText();
}

public String getLastName(){
    return jtfLast_name.getText();
}

public String getEntry(){
    return jtfEntry.getText();
}   
}

I am not looking for you to write me a solution, I am only looking for guidance as I cannot seem to find what I want on google. Such as a link to a tutorial, the oracle one isn’t very informative on this matter as I don’t want to update the row in the table but in the textfields.

  • 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-23T11:53:43+00:00Added an answer on May 23, 2026 at 11:53 am

    JTable has a ListSelectionModel, which you can access by getSelectionModel(). You can add a listener to it and get notified of row selection events. Listeners would need to implement the javax.swing.event.ListSelectionListener interface and would get notified via valueChanged(..). Your code will be something something similar to this:

    public ContestantAddPanel() implements ListSelectionListener {
    ...
    
       public valueChanged(ListSelectionEvent e) {
          ...
       }
    ...
    }
    

    And

    myTable.getSelectionModel().addListSelectionListener(<some instance of your panel>);
    

    This should be enough to get you started, but if you need more info please post a comment. I don’t have any links to a good tutorial, sorry.

    Edit:

    How to Write a List Selection Listener

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

Sidebar

Related Questions

Alright. I have implemented a custom JTable model that includes the whole @Override public
I have a JTable that I would like to display a fancy tooltip (basically
I have a JTable in Java that has a custom dataMOdel and custom renderer.
I have data from a database loaded into a JTable through a custom table
I Have a JTable where the data model contains information from a sql query.
I would like to have the editor in my editable JTables select all text
I have a JTable that is populated using a custom TableModel I created. I
So I have an editable Jtable (TreeTable actually) with a custom model. The current
I have implemented a custom Table Model as follows: public class MyTableModel extends AbstractTableModel
I have a JTable that holds several JPanels using a custom renderer/editor. The JPanel

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.