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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:39:03+00:00 2026-05-28T18:39:03+00:00

I have a csv file (5 columns, with | as delimiter) and I want

  • 0

I have a csv file (5 columns, with | as delimiter) and I want to fill 2 JTable columns with two data columns from csv file.

public class jTable extends JFrame {

    public static int rowNumber() {
        int num = 0;
        try {
            File files = new File("C:\\BorsaItalia2.csv");
            BufferedReader bf = new BufferedReader(new FileReader(files));
            String lines = "";
            while ((lines = bf.readLine()) != null) {
                num++;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return num;
    }
    JTable table;

    public jTable() {
        setLayout(new FlowLayout());
        String[] columnNames = {"a", "b", "c", "d", "e"};

        Object[][] data = new Object[rowNumber()][5];

        table = new JTable(data, columnNames);
        table.setPreferredScrollableViewportSize(new Dimension(600, 950));
        table.setFillsViewportHeight(true);

        JScrollPane scroll = new JScrollPane(table);
        add(scroll);
    }

    public static void main(String[] args) {
        try {
            int row = 0;
            int col = 0;

            Object[][] imported = new Object[rowNumber()][5];

            File file = new File("C:\\BorsaItalia2.csv");

            BufferedReader bfr = new BufferedReader(new FileReader(file));
            String line = "";

            while ((line = bfr.readLine()) != null) {

                StringTokenizer st = new StringTokenizer(line, "|");

                col = 0;
                while (st.hasMoreTokens()) {
                    imported[row][col] = st.nextToken();

                    System.out.println("number["+ row + "]["
                        + col + "]:" + imported[row][col]);
                    col++;
                }
                row++;
            }
            bfr.close();

            Object[] description = new Object[imported.length];
            Object[] symbol = new Object[imported.length];

            for (int i = 0; i < imported.length; i++) {
                description[i] = imported[i][2];
                symbol[i] = imported[i][0];
            }
            for (int i = 1; i < imported.length; i++) {
                System.out.println("Description is " + description[i]
                    + " and symbol is: " + symbol[i]);
            }
            System.out.println("");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            System.out.println("error " + e);
        }
        jTable gui = new jTable();
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setSize(650, 950);
        gui.setVisible(true);
        gui.setTitle("Project Table");
    }
}

I would like to fill table column a with Object[] symbol and column c with Object[] description.

Any coding help really appreciated.

Thanks all.

  • 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-28T18:39:04+00:00Added an answer on May 28, 2026 at 6:39 pm

    Instead of using the DefaultTableModel implied by your JTable constructor, create your own implementation of AbstractTableModel, as shown in How to Use Tables: Creating a Table Model. Arrange for your getValueAt() to return the data from the arrays you’ve read. There’s a related example here.

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

Sidebar

Related Questions

I have a csv file with 5 columns. I want to fetch the row
I have a .csv file containing 3 columns of data. I need to create
I have a .csv file that contains data for only certain columns in a
Background - I want to extract specific columns from a csv file. The csv
I currently have a .csv file with several unlabeled columns of data, which to
I have csv file with 14 columns and I want to sort it in
I have .csv file that contain 2 columns delimited with , . file.csv word1,word2
i have an input csv file with columns position_Id, Asofdate, etc which has to
I have a csv file, and I want to extract the each column a
I have CSV file and Macro in VBA. I want to open CSV file

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.