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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:42:40+00:00 2026-05-30T10:42:40+00:00

I have an (access) database table which contains data I would like to populate

  • 0

I have an (access) database table which contains data I would like to populate into a list in my java program. The table consists of multiple columms (id, name, etc)

What I would like is a JList listing all the name(s) and then when an item from the list has been double clicked I would like the id number for that item to be inserted into another table.

I have already implemented the list and populated it with the records from the db table (name column). What I’m having trouble with is when the user double-clicks on the item, how do I can I get get the ID for that video? The database call which populates the list selects multiple columns and puts them all into an array, not quite sure how I can link that list item to the array.

Here is what I got so far…

The java class

  ArrayList list = new ArrayList();
  ArrayList video = new ArrayList();
  list = VideoData.getVideoList();

  JList videolist = new JList();;  
  Vector data = new Vector();;  

  for (int i=0; i < list.size(); i++) {
           video = (ArrayList) list.get(i);
           data.addElement(video.get(3));
       }

  videolist.setListData(data);
  videolist.setSelectedIndex(0);
  videolist.addMouseListener(new ActionJList(videolist));
  videolist.setFixedCellWidth(300);
  add(new JScrollPane(videolist));

What getVideoList() contains

ArrayList list = new ArrayList();

try {
    ResultSet res = stmt.executeQuery("SELECT * FROM Items ORDER BY VidID ASC");
    while (res.next()) { // there is a result
      ArrayList sub = new ArrayList();
      sub.add(res.getString("VidID"));;
      sub.add(res.getString("Name"));
      sub.add(res.getString("Writer"));
       // add sub array  to list
      list.add(sub); 
    }
} catch (Exception e) {
    System.out.println(e);
    return null;
}

return list;

The current doulbe-click function is the following (which I found on the net)

  public void mouseClicked(MouseEvent e){     
   if(e.getClickCount() == 2){ // double click
     int index = list.locationToIndex(e.getPoint());
     ListModel dlm = list.getModel();
     Object item = dlm.getElementAt(index);;
     list.ensureIndexIsVisible(index);
     System.out.println("Double clicked on " + item);
     }
   }

.. From this item only tells me what is listed inside the JList cell, What I need to to be able to do is get the other array data for that selected item.

  • 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-30T10:42:42+00:00Added an answer on May 30, 2026 at 10:42 am

    (I have used generics <...> to make the code more readable.)

    As @HovercraftFullOfEels said, the JList may contain a entire video object:

    static class Video {
        String vidID;
        String name;
        String writer;
    
        @Override
        public String toString() {
            return writer; // For JList display
        }
    }
    

    The usage then goes as follows.

    List<Video> list = VideoData.getVideoList();
    
    JList videolist = new JList();
    
    Vector<Video> data = new Vector<Video>();  
    for (int i=0; i < list.size(); i++) {
        Video video = list.get(i);
        data.addElement(video);
    }
    
    videolist.setListData(data);
    videolist.setSelectedIndex(0);
    videolist.addMouseListener(new ActionJList(videolist));
    videolist.setFixedCellWidth(300);
    add(new JScrollPane(videolist));
    

    with getVideoList as:

    List<Video> getVideoList() {
    List<Video> list = new ArrayList<Video>();
    
    try {
        ResultSet res = stmt.executeQuery("SELECT VidID, Name, Writer FROM Items ORDER BY VidID ASC");
        while (res.next()) { // there is a result
            Video sub = new Video();
            sub.vidID = res.getString("VidID");
            sub.name = res.getString("Name");
            sub.writer = res.getString("Writer");
            list.add(sub); 
        }
            res.close();
    } catch (Exception e) {
        System.out.println(e);
        return null;
    }
    
    return list;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In an application we are developing, I have access to a database table which
I have an Access database in which I drop the table and then create
I have an access database which has some sql queries loaded into it. I
I have read-only access to a remote MySQL database, which contains a very large
I have read-only access to a remote MySQL database, which contains a very large
I have a ms access database that has one table for each photo album
I have a table in an Access 2007 database. All fields are of type
If I have a class representing access to one table in my database in
I have an Access database (in Access 2003) with several tables, and data must
I have an xls file i would like to read using c# and populate

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.