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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:03:28+00:00 2026-06-06T21:03:28+00:00

I am trying to have a window open and have it display the text

  • 0

I am trying to have a window open and have it display the text from a file. However when I run it, I simply get a blank window. Here is the code for the window – I get no errors from eclipse at all.

package presentation;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import domain.Items;
import services.exceptions.ItemNotFoundException;
import services.itemservice.*;

public class ShowAllInventory extends JFrame {

    /**
     * 
     */
    private static final long serialVersionUID = -4498395613773129897L;
    private JPanel contentPane;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    ShowAllInventory frame = new ShowAllInventory();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the window frame.
     */
    public ShowAllInventory() throws ItemNotFoundException {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);

        /**
         * Load the inventory
         */

        IItemsService service = new ItemsServiceImpl();
        try {
            Items items = service.getItems();
        } catch (ItemNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println ("Items Not Found");
        }

    }

}

Here is the code for the interface the code is calling –

    public Items getItems () throws ItemNotFoundException;

}

And here is the implementation…

/**
 * Getting Items from the database
 * @return 
 * @throws ItemNotFoundException
 */
@Override
public Items getItems() throws ItemNotFoundException {

    Items items = (Items) null;
    try {
        ObjectInputStream input = new
                ObjectInputStream (new FileInputStream("itemdatabase"));
        items = (Items)input.readObject();
        input.close();
    } catch (IOException ioe) {
        System.out.println ("IOException");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }       
    return items;       
}
  • 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-06T21:03:30+00:00Added an answer on June 6, 2026 at 9:03 pm

    I don’t know if your IItemsService can load the file properly. But most likely you get a blank window because in your code, I think you forgot to add a component to display the items. If your Items works as a List. You can use a JList to display them.

    Item[] items = ...// use your Items to populate Item to an array
    JList itemList = new JList(items);
    
    JScrollPane scrollPane = new JScrollPane(itemList);
    scrollPane.setPreferredSize(new Dimension(300, 100)); //put your preferred size here
    
    contentPane.add(scrollPane);
    

    IMHO, I think you should not throw ItemNotFoundException since finding no items should be a normal case. FileNotFoundException should be the one to be thrown here.


    UPDATED
    If you want to use JTextField or JTextArea you have to something like this:

    ...
    Items items = service.getItems();
    ...
    
    String itemContent = items.toString(); // you have to put meaningful information from class Items to this String
    JTextArea itemDisplay = new JTextArea(itemContent);
    // JTextField itemDisplay = new JTextField(itemContent);
    
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setPreferredSize(new Dimension(300, 100)); //put your preferred size here
    
    contentPane.add(scrollPane);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have other-window.xaml file and trying to open this from window.xaml on button click.
So I'm trying to have a window that I can drag around by the
I have a window with the following elements, and I'm trying to access the
I'm trying to hide window after its startup. I have own window-class which is
Currently, I'm trying to have a top-level window in Windows Forms with a custom
I have been trying to add to the Watch window a Java Date object
I have a Game Window to which I am trying to put W ,
I'm trying to create a preferences window. In it I have some checkbox style
I'm trying to intercept events using Gdk.Window.AddFilter(Gdk.FilterFunc) in Mono. So far, I have been
I'm trying to open a dialog window, but every time I try to open

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.