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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:30:52+00:00 2026-05-19T01:30:52+00:00

* SOLVED THANKS TO ALL WHO HELPED * Hello my q is about a

  • 0

*SOLVED THANKS TO ALL WHO HELPED *

Hello my q is about a jtable that i have ,i fill it with components from a .txt ,I have a main (menu ) JFrame and by pressing a jbutton i want the jtable to pop out ! My problem is that my jtable is blank and it supposed to show some date !I would appreciated any help , Thanks.
this is my ”reading” class`

public static void main(String[] args) {
     company Company=new company();
    payFrame jframe=new payFrame(Company);
    jframe.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
    jframe.setSize(600,300);
    jframe.setVisible(true);
     readClass();
}
    //diavasma
  public static void readClass(){
    ArrayList<Employee> emp =new ArrayList<Employee>() ;
    //Employee[] emp=new Employee[7];
    //read from file
 try {

   int i=0;
   // int rowCounter;
   // int payments=0;

String inputDocument = ("src/Employees.txt");


FileInputStream is = new FileInputStream(inputDocument);
Reader iD = new InputStreamReader(is);


BufferedReader buf = new BufferedReader(iD);
String inputLine;
while ((inputLine = buf.readLine()) != null) {
            String[] lineParts = inputLine.split(",");

            String email = (lineParts[7]);
            int EmpNo = Integer.parseInt(lineParts[0]);
            String type = lineParts[10];
            int PostalCode = Integer.parseInt(lineParts[5]);
            int phone = Integer.parseInt(lineParts[6]);
            int DeptNo = (short) Integer.parseInt(lineParts[8]);
            double Salary;
            int card = (short) Integer.parseInt(lineParts[10]);
            int emptype = 0;
             int hours=Integer.parseInt(lineParts[11]);
            if (type.equals("FULL TIME")) {
                emptype = 1;
            } else if (type.equals("SELLER")) {
                emptype = 2;
            } else {
                emptype = 3;
            }

            /**
             *  Creates employee instances depending on their type of employment
             *  (fulltime=1, salesman=2, parttime=3)
             */
            switch (emptype) {
                case 1:


                    Salary = Double.parseDouble(lineParts[10]);
                    emp.add(new FullTime(lineParts[1], lineParts[2], EmpNo, 
                            lineParts[3],
                            lineParts[4], PostalCode, phone,
                            email, DeptNo, card, Salary,hours, type));

                    i++;
                    break;

and this is my class where i make my Jtable and fill him

public class company extends JFrame {
    private ArrayList<Employee> emp = new ArrayList<Employee>();
    public void addEmployee(Employee emplo) {

    emp.add(emplo);
}

public ArrayList<Employee> getArray() {
    return emp;
}

public  void getOption1() {

     ArrayList<Employee> employee = getArray();
    JTable table = new JTable();
    DefaultTableModel model = new DefaultTableModel();
    table.setModel(model);
    model.setColumnIdentifiers(new String[]{"Code", "First Name", "Last Name", "Address", "City", "Postal Code", "Phone", "Email",
                "Dept Code", "Salary", "Time Card", "Hours"});
    for (Employee current : employee) {
        model.addRow(new Object[]{current.getempCode(), current.getfirst(), current.getlast(),
                    current.getaddress(), current.getcity(), current.getpostalCode(),
                    current.gettelephone(), current.getemail(), current.getdep(),
                    current.getsalary(), current.getcardcode(), current.getHours()
                });

    }


    table.setPreferredScrollableViewportSize(new Dimension(500, 50));
    table.setFillsViewportHeight(true);
    JScrollPane scrollPane = new JScrollPane(table);
    add(scrollPane);
   setVisible(true);

    table.revalidate();
  • 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-19T01:30:53+00:00Added an answer on May 19, 2026 at 1:30 am

    There’s a lot that could be improved about your code; in particular you should learn the Java naming conventions (Company instead of company; company Company=new company(); is exactly backwards of how you should be declaring your variables).

    Second, your class hierarchy doesn’t make sense – is a company really a JFrame? No. You should have a Company class that holds the employees, and then a CompanyFrame class that extends the JFrame and has a reference to the Company object.

    Third, you have not decomposed or isolated the problem. There are any number of reasons your table might be blank. Are you sure that your code reading the text file is working correctly? Are you sure that the list of Employee objects is created correctly? The easiest way to debug this stuff is to print out the state of your objects at various points in time and make assertions (e.g. assert employee.size() > 0 if you expect there to be more than one employee at a given point.)

    Finally, this goes for general programming – you have to be able to crawl before you can run. In other words, don’t start off trying to get everything working completely on the first pass. Before you deal with reading the employees from files, make sure you can get it working with some hardcoded employee objects that you create yourself, within code.

    Edit:

    One clue is that you read your employees in a public static void method:

    public static void readClass(){
        ArrayList<Employee> emp =new ArrayList<Employee>() ;
    

    where do you ever add those employees into the employee arraylist in your frame? You have an addEmployee method but it doesn’t seem to be called

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

Sidebar

Related Questions

I understand the problem that OSGI solved thanks to this question.... What does OSGi
UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
First of all, thanks to everyone who helps me, it is much appreciated! I
THIS PROBLEM IS NOW SOLVED. THANK YOU TO EVERYONE WHO REPLIED. Hello, I am
Thanks for all your help so far I have made the following changes This
I have a problem that's breaking my mind. I have a .txt file that
EDIT: SOLVED Thanks Brooks. Your question led me to keep digging into if the
SOLVED I misspelled the property department -> Department. Thanks for the answers and a
This problem has been solved! Thanks a lot to Brad, Denis and junkie! You're
How to adjust the font for the following:(solved) fontSize 40 BOLD Italicized Thanks The

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.