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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:04:55+00:00 2026-06-09T17:04:55+00:00

How to put a dropdown list that has the list of every string, and

  • 0

How to put a dropdown list that has the list of every string, and when I select a item on that list then push the load button it will only show up what’s on that String. Here’s my code, I actually put the number of the string and and show the String’s data using while statements.

How can I actually put a Dropdown list and it’s content will be a number registered on every string. Just like this

1 231231

2 123124

3 123124

4 232312

If I select 4 and press “Load” it will show “232312”
and everytime I save a data a unique number will be registered in every line, just like
“4” is the unique no. and 232312 is it’s data

package datasaving;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import javax.swing.*;

public class Datasaving {

    /**
     * @param args the command line arguments
     * @throws FileNotFoundException
     * @throws IOException  
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        JPanel panel = new JPanel();
        JFrame frame = new JFrame();
        final JTextField input0 = new javax.swing.JTextField(20);
        final JTextField input1 = new javax.swing.JTextField(20);
        final JTextField out = new javax.swing.JTextField(20);
        final JTextField line = new javax.swing.JTextField(20);

        JButton save = new javax.swing.JButton("Save");
        JButton load = new javax.swing.JButton("Load");
        frame.add(panel);
        frame.setSize(240,200);
        panel.add(input0);
        panel.add(input1);
        panel.add(save);
        panel.add(line);
        panel.add(out);
        panel.add(load);

        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setVisible(true);





        save.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                 File file = new File("data.dat");

                            try {
                                 try (FileWriter writer = new FileWriter(file, true)) {
                                 String data0 = input0.getText();
                                 String data1 = input1.getText();
                                 writer.write(data0+":"+data1+"\n");
                                }

                                System.out.println("Data Saved");
                                } catch (IOException | HeadlessException z) {
                                JOptionPane.showMessageDialog(null, e);
                                }
                                } 
                                });
        load.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {

                                 int lines = Integer.parseInt(line.getText());


                                     try {
                                 FileInputStream fs= new FileInputStream("data.dat");
                                 BufferedReader br = new BufferedReader(new InputStreamReader(fs));
                                 for(int i = 0; i < lines; ++i) {
                                 br.readLine();
                                 }
                                 out.setText(br.readLine());



                                JOptionPane.showMessageDialog(null, "Loaded");
                                } catch (   IOException | HeadlessException es) {
                                JOptionPane.showMessageDialog(null, e);
                                }
                                 }


                                });



    }
}

for example:
John blahblahblahblah
Keith blahblahblahblah
Joe blahblahblahblah
Kenneth blahblahblahblah
Christian blahblahblahblah
The first word “Names” will be added to JList or JComboBox
how to make the names a Array. I know how to use .split(); but I don’t know how to make that happen in every lines in the file

  • 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-09T17:04:56+00:00Added an answer on June 9, 2026 at 5:04 pm

    1) JTextField doesn’t support multi-line. Try JTextArea instead. With text areas, you can use myTextArea.append() to add lines as you read them.

    2) But actually, it sounds like a JComboBox or a JList might be what you’re really looking for:

    • http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html

    3) Your basic program looks OK

    ‘Hope that helps!

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

Sidebar

Related Questions

I have a dropdown list that I want to show only certain options when
I have a search form built in ASP.NET that has a dropdown list which
I have a dropdown select list on my page of class=TypeFilter. I have a
I have a page that contains dynamically generated Dropdown List controls and I want
My site has a number of dropdown lists that require an option called Other.
I have a dropdown list that auto submits a form and performs a search
I have a drop down list that needs to show content that has been
I have a drop down list and I want the selected value to put
How to put the first item on the DropDownList in blank ? In VB
So I am trying to put two inline dropdown lists. I tested and it

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.