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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:14:20+00:00 2026-06-07T04:14:20+00:00

I’m having more I’m hopeless at programming problems. I have a piece of code

  • 0

I’m having more “I’m hopeless at programming” problems.

I have a piece of code which uses StringBuilder to display elements of an array in a text panel of a GUI when the program starts. Here’s the StringBuilder code:

// memory tab
    StringBuilder mList = new StringBuilder();
    memLocList = new Memory[MEM_LOCATIONS];
    mem = new Memory();
    for (int i = 0; i < memLocList.length; i++) {
        memLocList[i] = mem;
        memLocList[i].setOpCode(00);
        mList.append(String.format("%10s %04x %10s %6s", "Address:   ", i,
                "Value:  ", memLocList[i].getOpCode()));
        mList.append("\n");
    }

JComponent memTab = makeTextPanel(mList.toString());
    tabs.addTab("Memory", new JScrollPane(memTab));

}

protected JComponent makeTextPanel(String t) {
    text = t;
    JPanel panel = new JPanel(false);
    JTextPane filler = new JTextPane();
    filler.setFont(new Font("Courier", Font.PLAIN, 14));
    filler.setText(text);
    filler.setAlignmentX(LEFT_ALIGNMENT);
    panel.setLayout(new GridLayout(1, 1));
    panel.add(filler);
    return panel;
}

The GUI also has a text entry panel where a String of hex values can be entered.

On clicking a button, the user is prompted for another value, which corresponds to the position in the array where the first hex value should be inserted.

Once these values have been entered, I’d like the display to be updated / refreshed to reflect this but am unsure of how to go about it.

I found this question here, which is similar but I’m not sure if implementing Observer/Observable pattern is the right way to proceed, and even if it is, how I’d go about it:
Best Way to Constantly Update GUI Elements

My initial approach was to add an “updateDisplay()” method, which I could call after processing the button click and re-call the makeTextPanel method:

public void updateDisplay() {

    makeTextPanel(text);
}

I thought this might refresh it but it has no effect of the display.

Any help appreciated.

  • 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-07T04:14:21+00:00Added an answer on June 7, 2026 at 4:14 am

    You hold your array in a model class, and you allow other classes to “listen” to this by giving this class a SwingPropertyChangeSupport object as well as an addPropertyChangeListener(…) method. Then give the array a setXXX(…) method, and in that method fire the SwingPropertyChangeSupport object after updating the array. There are examples of just this sort of thing on this site, some written by me.

    For example: here, here, here, …

    By the way, I’m not surprised that your call to makeTextPanel(text) doesn’t work. It creates a JPanel, but you don’t appear to do anything with the JPanel that is returned from the method. But nor should you. I don’t think that creating new JPanels is the solution you want, but rather updating the Strings displayed by a component of some sort such as a JList or JTextArea using the listener framework that I’ve described above.

    If any of this is confusing, please ask for clarification.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small

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.