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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:33:21+00:00 2026-05-26T23:33:21+00:00

I’m working on a program for a little store. When I click the button

  • 0

I’m working on a program for a little store. When I click the button “Report”, it must show a Table, like this one:

enter image description here

Column names “A”, “B”…”N”, must be the names of the employees. But I can’t figure out how.
Here is my code:

public void Inform()
{
    String[] employee;
    String[] product[];
    this.setLayout(null);

    Inform=new JTable(nulo, employee.length);

     model = new DefaultTableModel() {

            private static final long serialVersionUID = 1L;

            @Override
            public int getColumnCount() {
                return 1;
            }

            @Override
            public boolean isCellEditable(int row, int col) {
                return false;
            }

            @Override
            public int getRowCount() {
                return Inform.getRowCount();
            }
        };

        headerTable = new JTable(model);

       for (int i = 0; i < Inform.getRowCount(); i++) 
            headerTable.setValueAt(product[i], i, 0);


        headerTable.setShowGrid(false);
        headerTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        headerTable.setPreferredScrollableViewportSize(new Dimension(50, 0));
        headerTable.getColumnModel().getColumn(0).setPreferredWidth(50);

        scrollPane = new JScrollPane(Inform);
        scrollPane.setRowHeaderView(headerTable);
        scrollPane.setBounds(5,5,500,500);
        scrollPane.setEnabled(false);
        this.add(scrollPane);


}

Employee and product variates depending how many are entered. nulo is how many products are ready to sell.

  • 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-26T23:33:21+00:00Added an answer on May 26, 2026 at 11:33 pm

    You should add getColumnName() in your TableModel:

    String[] employee = {"Employee 1", "Employee 2"};
    
    @Override
    public String getColumnName(int index) {
        return employee[index];
    }
    

    In your case this could be:

    model = new DefaultTableModel() {
    
        private static final long serialVersionUID = 1L;
        String[] employee = {"Employee 1", "Employee 2"};
    
        @Override
        public int getColumnCount() {
             return employee.length;
        }
    
        @Override
        public boolean isCellEditable(int row, int col) {
             return false;
        }
    
        @Override
        public int getRowCount() {
             return Inform.getRowCount();
        }
    
        @Override
        public String getColumnName(int index) {
            return employee[index];
        }
    };
    

    And here is a fully working example:

    import javax.swing.JFrame; 
    import javax.swing.JScrollPane; 
    import javax.swing.JTable; 
    import javax.swing.table.DefaultTableModel; 
    
    public class TableNamesTest extends JFrame { 
    
        public TableNamesTest() { 
            DefaultTableModel model = new DefaultTableModel() { 
                String[] employee = {"emp 1", "emp 2"}; 
    
                @Override 
                public int getColumnCount() { 
                    return employee.length; 
                } 
    
                @Override 
                public String getColumnName(int index) { 
                    return employee[index]; 
                } 
            }; 
    
            JTable table = new JTable(model); 
            add(new JScrollPane(table)); 
            pack(); 
            setDefaultCloseOperation(EXIT_ON_CLOSE); 
            setVisible(true); 
        } 
    
        public static void main(String[] args) { 
            new TableNamesTest(); 
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.