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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:08:05+00:00 2026-06-13T04:08:05+00:00

I have written some code which is designed to create a table and display

  • 0

I have written some code which is designed to create a table and display the clipboard data (which will be copied from excel) in that table.

So i have one menu item in the menu bar “Import from Excel”, which when clicked will take whatever excel data is in the clipboard and display a table in the panel below.

Also, I’ve written it so that the panel (in which the table is displayed) is capable of being switched depending on any future menu buttons which could lead to a completely different panel being displayed below.

So I have this DisplayExcelData class which implements a MainPage interface (which contains an init method). When the menu item is clicked, it fires an action event in the extended menubar class, which feeds the content pane the MainPage interface associated with that menu item (in this case DisplayExcelData is fed to the content pane when “Import from Excel is clicked), then init is called and it is added to the content pane.

When the program launches and nothing has been selected, it defaults to a InitialScreen class.

The DisplayExcelData class looks like this:

public class DisplayExcelData implements MainPageIF
{
    private ExcelTableModel tm = null;
    private Table table = new Table();
    private JPanel thisPanel = new Panel();

    public DisplayExcelData () 
    {
        super();
        thisPanel.setLayout(new BorderLayout());
    }

    @Override
    public void init()
    {
                //the test data I have been using is only 2 columns, so I'm just using
                //these as test columns at the moment
        tm = new ExcelTableModel("First, Second");
        table.setModel(tm);

        thisPanel.add(table, BorderLayout.CENTER);
    }

    @Override
    public JPanel getPanel()
    {
        return thisPanel;
    }
}

the ExcelTableModel takes the data in the clipboard and turns it into a TableModel

Then, in the contentPane, I have

public MainFrame()
{
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(50, 50, 800, 500);
    compInit();
}

private void compInit() 
{
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    contentPane.setBackground(new Color(0,0,0));
    setContentPane(contentPane);

            //mf is the menu bar which is a class variable
    MenuBar menuBar = mf.getMenuBar();

    setPanelFromMenuBar();

    setMenuBar(menuBar);
}

private void setPanelFromMenuBar()
{
    MainPageIF page = mf.getPage();
    if (page == null)
    {
        page = new InitialScreen();
    }
    page.init();
            //mainPanel is a class variable
    mainPanel = page.getPanel();

    mainPanel.setVisible(true);
    contentPane.add(mainPanel, BorderLayout.CENTER);
}

@Override
public void actionPerformed(ActionEvent evt)
{
    Object source = evt.getSource();
    if (source instanceof MenuItem)
    {
        contentPane.removeAll();
        setPanelFromMenuBar();
        getContentPane().doLayout();
            update(getGraphics());
    }
}

If I change the code so I boot the program with the DisplayExcelData class as the initial screen, it works…it takes the excel data in the clipboard and displays it wonderfully in a table on the screen…if however, i insist that this table be displayed when i click on the MenuItem, it just displays a blank screen. When I debug, and check what mainPanel has in it…it contains the correct TableModel with the Excel data, contained in a JTable…but it wont display…I’m ripping my hair out as to why…

Can anyone help?

  • 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-13T04:08:06+00:00Added an answer on June 13, 2026 at 4:08 am
    • I would not recommend extending JFrame class
    • Use Anonymous inner class listeners instead of implementing ActionListener (unless the ActionListener must be accessible by other classes)

    As for your actual problem:

    Try calling revalidate() and repaint() on your JFrame instance after removing components and adding the new component:

     contentPane.removeAll();//remove
     setPanelFromMenuBar();//add
    
     revalidate();//refresh ui and layout
     repaint();
    

    Or alternatively have a look at the CardLayout which allows flipping between JComponents like JPanels via CardLayout#show(...)

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

Sidebar

Related Questions

I have written some code, which will ask for confirmation before leaving the page.
I have written some code which extracts and invoice from various hashes, arrays, arrays
I have written some code in JSP to download .docx files which is hosted
Let's assume I have a framework written in Java and some C++ code which
I have code written in c, which contains some complex algorithms and I want
I have written some code to display a YouTube video on my page but
Context: Windows7, VBScript, ADODB and ADOX. I have written some VBScript code which creates
I have written some code which produces simple animations based on cycling through a
I have written some code which passes values between java and c using jni.
I have written some code which compiles fine under linux but on Solaris 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.