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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:04:21+00:00 2026-05-16T07:04:21+00:00

OK so whenever I open up a new appelt window with my code… the

  • 0

OK so whenever I open up a new appelt window with my code… the JList does not show UNTIL I click on it… how do i make it so all values appear when i start the applet?

thanks.

import java.awt.*;
import javax.swing.*;
import javax.swing.JList;
import java.awt.event.*;
import java.util.*;

public class inventory extends JApplet implements MouseListener {

    public static String newline;
    public static JList list;
    int gold = 123;

    public void init() {

        ArrayList<String> arr = new ArrayList<String>();
        arr.add("Hatchet");
        arr.add("Sword");
        arr.add("Shield");
        arr.add(gold + " Gold");
        System.out.println("You have " + arr.size() + " items in your inventory.");
        showInventory(arr);

        list = new JList(arr.toArray());

        add(list);

        list.addMouseListener(this);

        list.setVisible(true);
    }

    public static void showInventory(ArrayList<String> theList) {
        for (int i = 0; i < theList.size(); i++) {
            System.out.println(theList.get(i));
        }
    }

    public void mousePressed(MouseEvent e) {
    }

    public void mouseReleased(MouseEvent e) {
        Object index = list.getSelectedValue();
        System.out.println("You have selected: " + index);
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void paint(Graphics g) {
    }
}
  • 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-05-16T07:04:21+00:00Added an answer on May 16, 2026 at 7:04 am

    You want

    this.setVisible(true);
    

    rather than

    list.setVisible(true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the code below to open a new window whenever user presses F2
Whenever I open a new terminal window I now get: -bash: /usr/local/bin/heroku: /usr/local/bin/ruby: bad
when ever i use window.location.href=//some url it always open a new window, this only
I'm not sure if it's just me, but whenever I open .txt files in
Whenever I open a new (web) project in VS 2010 the default build configuration
I want to have a new console open whenever I create a new thread
I'm fairly new to Sharepoint 2010 development. Whenever I need to make a UI
My VS 2003 is not working. Whenever I try to create a new project
I can open a new window using window.open() in ExternalInterface.call() but then I want
Whenever i open any new project in Visual Studio, a partial class is created.

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.