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

  • Home
  • SEARCH
  • 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 8770411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:33:18+00:00 2026-06-13T17:33:18+00:00

I really dont even know what to ask but to post the code and

  • 0

I really dont even know what to ask but to post the code and to put the error message here. The program should make a window with two tabs and a table of scores in each tab.

package components;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JTextPane;

public class TopLevelDemo extends JPanel{
    public TopLevelDemo() {
        JTabbedPane tabbedPane = new JTabbedPane();
        String[] players = new String[4];
        Object[][] singlesScores = new Object[2][4];
        Object[][] doublesScores = new Object[2][4];
        createScores(singlesScores);
        createScores(doublesScores);

        JComponent panel1 = makeScoreTable(singlesScores, players, 0, 0);
        tabbedPane.addTab("Singles",panel1);
        tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

        JComponent panel2 = makeScoreTable(doublesScores, players, 0, 0);
        tabbedPane.addTab("Doubles", panel2);
        tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);

        add(tabbedPane);
        tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    }
    protected JComponent makeScoreTable(Object[][] scores, String[] players, int x, int y) {
        JPanel panel = new JPanel(true);
        JTable table = new JTable(scores, players);
        GridBagConstraints c = new GridBagConstraints();
        c.gridx=x;
        c.gridy=y;
        panel.add(table, c);
        return panel;
    }
    protected JComponent makeTextPanel(String text) {
        JPanel panel = new JPanel(true);
        JLabel filler = new JLabel(text);
        filler.setHorizontalAlignment(JLabel.CENTER);
        panel.setLayout(new GridLayout(10, 25));
        panel.add(filler);
        return panel;
    }
    private static void createAndShowGUI() {
        JFrame frame = new JFrame("TopLevelDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.add(new TopLevelDemo(), BorderLayout.CENTER);
        frame.pack();
        frame.setVisible(true);
    }
     private Object[][] createScores(Object[][] scores) {
        scores[0][0]= new String("Home");
        scores[0][1]= new Integer(0);
        scores[0][2]= new Integer(0);
        scores[0][3]= new Integer(0);
        scores[1][0]= new String("Away");
        scores[0][1]= new Integer(0);
        scores[0][2]= new Integer(0);
        scores[0][3]= new Integer(0);
        return scores;
    }
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                UIManager.put("swing.boldMetal", Boolean.FALSE);
                createAndShowGUI();
            }
        });
    }
}

And then i get the error

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at javax.swing.JTable$1.getColumnName(JTable.java:665)
    at javax.swing.JTable.addColumn(JTable.java:2770)
    at javax.swing.JTable.createDefaultColumnsFromModel(JTable.java:1264)
    at javax.swing.JTable.tableChanged(JTable.java:4374)
    at javax.swing.JTable.setModel(JTable.java:3676)
    at javax.swing.JTable.<init>(JTable.java:612)
    at javax.swing.JTable.<init>(JTable.java:553)
    at javax.swing.JTable.<init>(JTable.java:664)
    at components.TopLevelDemo.makeScoreTable(TopLevelDemo.java:30)
    at components.TopLevelDemo.<init>(TopLevelDemo.java:17)
    at components.TopLevelDemo.createAndShowGUI(TopLevelDemo.java:49)
    at components.TopLevelDemo.access$000(TopLevelDemo.java:8)
    at components.TopLevelDemo$1.run(TopLevelDemo.java:68)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:666)
    at java.awt.EventQueue.access$400(EventQueue.java:81)
    at java.awt.EventQueue$2.run(EventQueue.java:627)
    at java.awt.EventQueue$2.run(EventQueue.java:625)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:636)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Anybody have any idea what I did wrong or poorly?

  • 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-13T17:33:19+00:00Added an answer on June 13, 2026 at 5:33 pm

    You need to assign values to the table column names.

    A string array of

    String[] players = new String[4];
    

    creates an an array of 2 Strings each with default value null. You could use:

    String[] players = { "Player 1", "Player 2", "Player 3", "Player 4" };
    

    Update:

    Adding a JTable directly onto the score panel does not allow all of the client area to be displayed. To fix, you could place it in a JScrollPane:

    panel.add(new JScrollPane(table), c);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure if I should or even can ask this here, but this is
I keep getting this error and I really dont know why. I have tried
I want to copy an svg group but I really dont know what I
I dont really know how to explain exactly what function i need but ill
im trying to achieve something but i dont really know how I have set
After watching Sussman's lecture http://www.infoq.com/presentations/We-Really-Dont-Know-How-To-Compute , I am inspired to give core.logic and core.match
So far I have the expression: http://[^\.]*\.mydomain\.com/((.*?)) Which matches... http://www.mydomain.com/Images/favicon.ico But I really dont
I am not a DBA and so dont really know anything about SQL 2005
This is going to be a really dumb question, I just know it, but
Ok, this is so impossible that I don't really know how to ask. I'm

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.