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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:50:02+00:00 2026-06-17T16:50:02+00:00

I have been working on an app, where you set up a list of

  • 0

I have been working on an app, where you set up a list of categories with items in it, which will then be made into a text file. But the GUI I’ve made for it doesn’t work entirely. I think the error is situated in the JMenuItem called Cat (or “add category”) or in the way I display the Categories (Update() method). It is supposed to ask for a name, make a Category named after that and display it in a JScrollPane, but nothing comes up. Here is the code:

public class GUIBuilder {
    public JFrame frame;
    public JPanel LeftPanel;
    public JPanel RightPanel;
    public JScrollPane scroll;
    public JMenuBar bar;
    public JMenu File;
    public JMenu Add;
    Inventory inv;

    public void go() {
        frame = new JFrame();

        scroll = new JScrollPane();

        bar = new JMenuBar();
        File = new JMenu("File");
        Add = new JMenu("Add...");
        bar.add(File);
        bar.add(Add);

        JMenuItem Save = new JMenuItem(new AbstractAction("Save") {
            private static final long serialVersionUID = 1L;

            public void actionPerformed(ActionEvent arg0) {

            }
        });
        JMenuItem Load = new JMenuItem(new AbstractAction("Load") {
            private static final long serialVersionUID = 1L;

            public void actionPerformed(ActionEvent arg0) {

            }
        });
        JMenuItem Generate = new JMenuItem(new AbstractAction("Generate Text File") {
            private static final long serialVersionUID = 1L;

            public void actionPerformed(ActionEvent arg0) {

            }
        });
        File.add(Save);
        File.add(Load);
        File.add(Generate);

        JMenuItem Cat = new JMenuItem(new AbstractAction("Add Category") {
            private static final long serialVersionUID = 1L;
            JFrame Cat;

            public void actionPerformed(ActionEvent arg0) {
                Cat = new JFrame("Add Category");
                final JTextField name = new JTextField(15);
                JButton Submit = new JButton(new AbstractAction("Submit") {
                    private static final long serialVersionUID = 1L;

                    public void actionPerformed(ActionEvent arg0) {
                        String n = name .getText();
                        if (n != null) {
                            inv.addCategory(new Category(n));
                            pullThePlug();
                            GUIBuilder.this.Update();
                        }
                    }
                });
                Cat.setLayout(new BorderLayout());
                Cat.add(name, BorderLayout.CENTER);
                Cat.add(Submit, BorderLayout.SOUTH);
                Cat.setSize(250, 150);
                Cat.setVisible(true);
            }
            public void pullThePlug() {
                WindowEvent wev = new WindowEvent(Cat, WindowEvent.WINDOW_CLOSING);
                Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
            }
        });
        JMenuItem item = new JMenuItem(new AbstractAction("Add Item") {
            private static final long serialVersionUID = 1L;

            public void actionPerformed(ActionEvent arg0) {

            }
        });
        Add.add(Cat);
        Add.add(item);

        frame.setJMenuBar(bar);
        frame.setSize(500, 800);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        frame.add(scroll);

        inv = new Inventory();
    }

    public void Update() {
        for (int i = 0; i < inv.categories.size(); i++) {
            Category cat = inv.categories.get(i);
            JPanel p = new JPanel();
            JTextPane name = new JTextPane();
            name.setText(cat.getName());
            scroll.add(p);
        }
    }
}

Thanks in advance 😉

  • 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-17T16:50:03+00:00Added an answer on June 17, 2026 at 4:50 pm

    You need to add your JTextPane name to your JPanel p.

    (It also seems to me that you’re missing a main method that will construct a GUIBuilder – but maybe that’s in another file that you haven’t shown in your question?)


    Also, if you create an empty JScrollPane, you need to add components via scrollpane.getViewport().add(yourcomponent);.

    You also need some layout management. The easiest way (and probably what you intended to do anyways) is:

        public void Update() {
            JPanel p = new JPanel();
            for (int i = 0; i < inv.categories.size(); i++) {
                Category cat = inv.categories.get(i);
                JTextPane name = new JTextPane();
                p.add(name);        
                name.setText(cat.getName());                
            }
            scroll.getViewport().add(p);       
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on test framework, which creates a new app domain to
I'm diving into iOS development and have been working on an alarm clock app
I have an MFC app which I have been working on for a few
I have been working on this app for at least 3-4 months and just
I have been working on an app where I have successfully shown my location
I have been working on an iOS App for sometime now and its almost
I have been working on a django app on my local computer for some
I have been working on getting a mail app to work from a tutorial
I have been working on a Windows Mobile app for a little while now
I have been working on a small php app (400K total). But in the

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.