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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:43:31+00:00 2026-06-11T16:43:31+00:00

I have a GUI setup with with buttons on them and a JTextArea .

  • 0

I have a GUI setup with with buttons on them and a JTextArea.

I also have an array of Strings with say size of 3.

What I want to do is use an action listener in a way that when the button called “next” is pressed, the JTextArea will then show the next cell in the array. The only problem is it displays the array at the same time. I need it to display the next cell when the button is hit

Can anyone help me with the code? Please and thank you.

 final ActionListener m2 = new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) 
    { 
        arr = new String[3];
        arr[0]= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";      
        arr[1]= "sssssssssssssssssssssss";
        arr[2]= "xxxxxxxxxxxxxxxxxxxxx";

        for (int i = 0; i<arr.length; i++){
        text.append(arr[i]);
        }
    }
};

next.addActionListener(m2);
  • 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-11T16:43:32+00:00Added an answer on June 11, 2026 at 4:43 pm

    So the basic concept is. You need a index value to maintain the current index of the array that is being displayed.

    From there, each time the user clicks next, you would increment the index and display the next value in the String

    public void actionPerformed(ActionEvent e) {
    
        currentIndex++;
        // You need to decide what to do when we reach the end of the array...
    
        String value = myStrings[currentIndex];
        textArea.setText(value);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a GUI that will setup the pivot table. For example, I
I have to setup a basic JAVA application including a GUI based on swing.
I have a GUI app that is getting to be quite slow. I want
I want to have Buttons next to each other on the same line, and
I have created for my plugin a start GUI with 3 buttons. This works
I would like to have a GUI setup like the diagram below. The JLayeredPane
I have a two panel wxPython GUI set up. In my right panel, I
I have to set up a Qt development environment for my GUI class. I
I have a program with a GUI interface whose initial set-up I need to
Basically I have my Emacs set up so it has a GUI specific elisp,

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.