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

  • Home
  • SEARCH
  • 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 6704247
In Process

The Archive Base Latest Questions

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

I’m posting the full code below, but basically I have a class which has

  • 0

I’m posting the full code below, but basically I have a class which has a dialog containing a scrollpane that holds a jlist. It is set to “DISPOSE_ON_CLOSE”, and I’ve tried setting every single variable that is ever created to null after the value is obtained, yet javaw.exe will continue to run indefinitely unless I forcibly close it.

In case more information is needed, here’s a quick explanation. This class is meant to create a dialog and show it, wait for the user input, and return the chosen text. It already does this. But for some reason, it continues to run in the background after it’s finished.

This is meant for an application, so having Java run in the background non-stop is not an appealing prospect. I really don’t know what else to try at this point. Below is my code.

package (REMOVED);

import java.awt.BorderLayout;
import java.awt.Dialog.ModalityType;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.WindowConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class PatientScrollPane implements ListSelectionListener, MouseListener {
    private String currentPatient;
    private JList patientList;
    private JDialog dialog;
    private JFrame frame;
    private JScrollPane scrollPane;
    private static int MAX_VISIBLE_ROW_COUNT = 15;

    public void setDialog(JDialog dialog) {
        this.dialog = dialog;
    }

    public JList getPatientList() {
        return patientList;
    }

    public void setPatientList(JList patientList) {
        this.patientList = patientList;
    }

    public String getCurrentPatient() {
        return currentPatient;
    }

    public void setCurrentPatient(String currentPatient) {
        this.currentPatient = currentPatient;
    }

    public JDialog getDialog() {
        return dialog;
    }

    public JFrame getFrame() {
        return frame;
    }

    public void setFrame(JFrame frame) {
        this.frame = frame;
    }

    public JScrollPane getScrollPane() {
        return scrollPane;
    }

    public void setScrollPane(JScrollPane scrollPane) {
        this.scrollPane = scrollPane;
    }

    public PatientScrollPane() {
        this(null);
    }

    public PatientScrollPane(JComponent locationRelativeToComponent) {
        this(locationRelativeToComponent, new JList(fakePatientList()));
    }

    public PatientScrollPane(JComponent locationRelativeToComponent, JList patientList) {
        this.patientList = patientList;
        patientList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        frame = new JFrame("Patient List");

        dialog = new JDialog(frame);
        dialog.setLocationRelativeTo(locationRelativeToComponent);

        patientList.addListSelectionListener(this);
        patientList.addMouseListener(this);
        setVisibleRowCount();

        scrollPane = new JScrollPane(patientList);
        dialog.getContentPane().add(scrollPane, BorderLayout.CENTER);

        dialog.pack();
        dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        dialog.setModalityType(ModalityType.APPLICATION_MODAL);
        dialog.setVisible(true);
    }

    private void setVisibleRowCount() {
        int size = patientList.getModel().getSize();

        if(size <= MAX_VISIBLE_ROW_COUNT) {
            patientList.setVisibleRowCount(size);
        } else {
            patientList.setVisibleRowCount(MAX_VISIBLE_ROW_COUNT);
        }
    }

    public static String[] fakePatientList() {
        String[] patients = new String[20];
        for(int i = 0; i < patients.length; i++) {
            patients[i] = "Patient " + i;
        }

        return patients;
    }

    public static String getPatient() {
        PatientScrollPane patientScrollPane = new PatientScrollPane();
        String patient = patientScrollPane.getCurrentPatient();
        patientScrollPane.setPatientList(null);
        patientScrollPane.setDialog(null);
        patientScrollPane.setCurrentPatient(null);
        patientScrollPane.setFrame(null);
        patientScrollPane.setScrollPane(null);
        patientScrollPane = null;

        return patient;
    }

    public static String getPatient(JComponent locationRelativeToComponent) {
        PatientScrollPane patientScrollPane = new PatientScrollPane(locationRelativeToComponent);

        return patientScrollPane.getCurrentPatient();
    }

    public static String getPatient(JComponent locationRelativeToComponent, JList patientList) {
        PatientScrollPane patientScrollPane = new PatientScrollPane(locationRelativeToComponent, patientList);

        String patient = patientScrollPane.getCurrentPatient();
        return patient;
    }

    @Override
    public void valueChanged(ListSelectionEvent e) {
        currentPatient = (String)patientList.getSelectedValue();
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        int index = patientList.locationToIndex(e.getPoint());
        patientList.setSelectedIndex(index);
        dialog.dispose();
    }

    @Override
    public void mouseEntered(MouseEvent e) {}

    @Override
    public void mouseExited(MouseEvent e) {}

    @Override
    public void mousePressed(MouseEvent e) {}

    @Override
    public void mouseReleased(MouseEvent e) {}

    public static void main(String[] args) {
        String patient = PatientScrollPane.getPatient();

        System.out.println("Chosen patient: " + patient);
    }
}

(I tried looking high and low for a solution to a similar problem, but it’s sort of too generic to find.)

  • 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-26T07:16:01+00:00Added an answer on May 26, 2026 at 7:16 am

    As long as your JFrame exists, the event dispatch thread will keep running and will keep the JVM alive since the JFrame, a top-level window initiates a non-daemon thread.

    For more on this, please look here.

    And for example,…

    import javax.swing.JDialog;
    import javax.swing.JFrame;
    
    public class DialogAndDaemons {
       public static void main(String[] args) {
          JFrame frame = new JFrame();
    
          JDialog dialog = new JDialog(frame, "Dialog");
          dialog.pack();
          dialog.setLocationRelativeTo(null);
          dialog.setVisible(true);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
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
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.