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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:06:46+00:00 2026-06-11T21:06:46+00:00

The Jtable doesn’t show column headers. I’m using vectors to populate the JTable, but

  • 0

The Jtable doesn’t show column headers. I’m using vectors to populate the JTable, but still it doesn’t seem to work. Here’s the code:

public class InsertFileToJtable extends AbstractTableModel{
Vector data;
Vector columns;
private String[] colNames = {"col1","col2","col3","col4","col5","col6","col7","col8"};


public InsertFileToJtable() {
String line;
data = new Vector();
columns = new Vector();
  try {
        FileInputStream fis = new FileInputStream("ProcessList.txt");
        BufferedReader br = new BufferedReader(new InputStreamReader(fis));
        StringTokenizer st1 = new StringTokenizer(br.readLine(), " ");
        while (st1.hasMoreTokens())
                columns.addElement(st1.nextToken());
        while ((line = br.readLine()) != null) {
                StringTokenizer st2 = new StringTokenizer(line, " ");
                while (st2.hasMoreTokens())
                       data.addElement(st2.nextToken());
        }
        br.close();
} catch (Exception e) {
        e.printStackTrace();
}  

}

public int getRowCount() {
return data.size() / getColumnCount();
}

public int getColumnCount() {
return columns.size()-1;
}

public Object getValueAt(int rowIndex, int columnIndex) {
return (String) data.elementAt((rowIndex * getColumnCount())
                + columnIndex);
}
@Override
public String getColumnName(int column) {
return colNames[column];
}
@Override
public Class getColumnClass(int col){
return getValueAt(0,col).getClass();
}
}

Here’s how the table is called from Main:

public static void main(String[] args) {
    InsertFileToJtable model = new InsertFileToJtable();
    JTable table = new JTable(model);
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);
    table.setModel(model);
    JScrollPane scrollpane = new JScrollPane(table);
    scrollpane.setViewportView(tabbedPane);
    tabbedPane.addTab("Process",null,table,"");
    model.fireTableStructureChanged();
    JPanel panel = new JPanel();
    panel.add(scrollpane);
    frame.add(panel);
    }

As I’m a newbie, I dont have any clue of what’s wrong. Any help would be highly appreciated. Thanks!

  • 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-11T21:06:47+00:00Added an answer on June 11, 2026 at 9:06 pm

    In order for the table to be able to display it’s headers, you need to add the table to a scroll pane.

    You started out okay, but then went and removed it by changing the scroll pane’s viewport

    // This was good
    JScrollPane scrollpane = new JScrollPane(table);
    // Then you changed it
    scrollpane.setViewportView(tabbedPane);
    // Then you added it to the tabbed pane
    tabbedPane.addTab("Process",null,table,"");
    

    Try adding the table back onto a scroll pane and add that to the tabbed pane

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

Sidebar

Related Questions

I followed some tips in this guide: JTable with horizontal scrollbar but still having
I am trying to add a JScrollPane to my JTable , but it doesn't
there's my code, it doesn't work because shows emty table without any rows ir
I am having this problem of setting column width of JTable. The code below
My question concerns removing the borders of column headers in JTable. My class extends
I have a jTable with two columns.First column is set as Boolean(for checkbox) and
I have this code to get a row from a JTable that is generated
I use the following program for creating JTable using java class. If I get
I'm trying to create a JTable with 2 columns, one must show the name
I've figured out how to get a JTable to be sorted properly, but I

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.