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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:25:46+00:00 2026-05-30T17:25:46+00:00

import java.awt.event.*; import java.io.File; import javax.swing.*; public class Launch extends JFrame implements ActionListener {

  • 0
import java.awt.event.*;
import java.io.File;
import javax.swing.*;

public class Launch extends JFrame implements ActionListener {
private static final long serialVersionUID = 5291490384908841627L;
JButton OK, create;
JList<String> players;
File player;
public static void main(String[] args) {
    new Launch();
}
private Launch() {
    this.setSize(600, 600);
    this.setLocationRelativeTo(null);
    this.setTitle("A Word Game");
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    Box box = Box.createVerticalBox();
    OK = new JButton("OK");
    create = new JButton("Create new player");
    OK.addActionListener(this);
    create.addActionListener(this);
    String[] playerList = getPlayers();
    players = new JList<String>(playerList);
    players.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane scroll = new JScrollPane(players, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.add(players);
    final JLabel choosePrompt = new JLabel("Choose a player.");
    box.add(Box.createVerticalStrut(20));
    box.add(choosePrompt);
    box.add(Box.createVerticalStrut(20));
    box.add(scroll);
    box.add(Box.createVerticalStrut(20));
    box.add(OK);
    box.add(Box.createVerticalStrut(20));
    box.add(create);
    box.add(Box.createVerticalStrut(20));
    this.add(box);
    this.setVisible(true);
}
private String[] getPlayers() {
    File playerDirectory = new File("players");
    File[] playersInFiles = playerDirectory.listFiles();
    String[] players = new String[playersInFiles.length];
    for (int counter = 0; counter < playersInFiles.length; counter ++) {
        players[counter] = trimTXT(playersInFiles[counter].getName());
    }
    return players;
}
private String trimTXT(String original) {
    return original.substring(0, original.length() - 4);
}
@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource().equals(OK)) {
        String name = players.getSelectedValue();
        if (name == null) {
            return;
        }
        player = new File(name + ".txt");
    } else if (e.getSource().equals(create)) {
        //create a new character, all that what-not
    }
}
}

The problem is that the players don’t show up in the JScrollPane. The scroll pane is just there without anything inside it. I have a bunch of blank .txt files representing players in the players folder. They are just for testing. The weid thing is that when the JList is not in the JScrollPane, it works fine. When I add it to a JScrollPane, then the stuff inside doesn’t show up.

  • 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-30T17:25:48+00:00Added an answer on May 30, 2026 at 5:25 pm
    import java.awt.event.*;
    import java.io.File;
    import javax.swing.*;
    
    public class Launch extends JFrame implements ActionListener {
    private static final long serialVersionUID = 5291490384908841627L;
    JButton OK, create;
    JList players;
    File player;
    public static void main(String[] args) {
        new Launch();
    }
    private Launch() {
        // don't do this
        this.setSize(600, 600);
        this.setLocationRelativeTo(null);
        this.setTitle("A Word Game");
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        Box box = Box.createVerticalBox();
        OK = new JButton("OK");
        create = new JButton("Create new player");
        OK.addActionListener(this);
        create.addActionListener(this);
        String[] playerList = getPlayers();
        players = new JList(playerList);
        players.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JScrollPane scroll = new JScrollPane(players, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        //scroll.add(players);
        final JLabel choosePrompt = new JLabel("Choose a player.");
        box.add(Box.createVerticalStrut(20));
        box.add(choosePrompt);
        box.add(Box.createVerticalStrut(20));
        box.add(scroll);
        box.add(Box.createVerticalStrut(20));
        box.add(OK);
        box.add(Box.createVerticalStrut(20));
        box.add(create);
        box.add(Box.createVerticalStrut(20));
        this.add(box);
        pack();
        this.setVisible(true);
    }
    private String[] getPlayers() {
        /*File playerDirectory = new File("players");
        File[] playersInFiles = playerDirectory.listFiles();
        String[] players = new String[playersInFiles.length];
        for (int counter = 0; counter < playersInFiles.length; counter ++) {
            players[counter] = trimTXT(playersInFiles[counter].getName());
        }*/
        String[] players = {"Bob", "Jane"};
        return players;
    }
    private String trimTXT(String original) {
        return original.substring(0, original.length() - 4);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource().equals(OK)) {
            String name = (String)players.getSelectedValue();
            if (name == null) {
                return;
            }
            player = new File(name + ".txt");
        } else if (e.getSource().equals(create)) {
            //create a new character, all that what-not
        }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class File { private JFrame frame1; private
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class tictac2 implements ActionListener{ static
Here I found this code: import java.awt.*; import javax.swing.*; public class FunWithPanels extends JFrame
package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.*; public class
Here is the code: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class TestGrid {
import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileNotFoundException; import java.io.IOException; import javax.swing.JButton; import javax.swing.JFrame;
Here is the code: import javax.swing.SwingUtilities; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JLabel; import java.awt.event.*;
Here is my code: import javax.swing.*; import java.awt.*; public class PanelModel { public static
Consider: import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.crypto.*; import javax.crypto.spec.*; import java.security.*; import
import java.awt.*; import java.awt.image.*; import java.awt.event.*; import javax.imageio.*; import java.lang.*; import java.io.*; import javax.swing.*;

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.