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

The Archive Base Latest Questions

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

I am currently building an application in Java on Eclipse as a self help

  • 0

I am currently building an application in Java on Eclipse as a self help guide to programming fundamentals and basic java programming, this is purely educational and for the sole purpose of being able to reference topics easily and practice my programming as I learn them by programming them into this tutorial application.

The content of the application will expand as time goes on and as I learn more components of programming.

So my first question comes down to correct form.

I am using a drop down box (JComboBox) so as to select specific topics from within the GUI. I would like to populate the list and keep the program clean and tidy. So my question is how would one populate the JComboBox so as to limit cluttering code. Perhaps a text file from which I could add topics to separately and edit more efficiently? I am after correct programming procedure as opposed to all the ways I could do it. I know I could use an ArrayList, however I am keen to understand the choices taken when using large amounts of content as opposed to very little.

Thanks,

Simon

  • 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-06T16:43:47+00:00Added an answer on June 6, 2026 at 4:43 pm

    I think the cleanest way is to define a custom ComboBoxModel.

    This way you can define a data model for your combobox, separating the part in which the combobox is created from the data management itself.

    Probably using a text file is a good thing, since you don’t have to modify the code when a new entry is inserted. You can define the reading file procedure inside your ComboBoxModel constructor. This way every time you run the program you’ll find updated combobox’s contents.

    ArrayList isn’t a good choice if the contents can’t be updated by the application itself. If you are hardcoding the contents of an arraylist, you will be forced to modify the code every time you need to add a new entry.

    A little example:

    class YourModel implements ComboBoxModel{
    
    //implements all interface methods required...
    @override
    public YourModel(String filename)
    {
        comboBoxItemList = new ArrayList<String>();
        // open your file
        // add every entry to the the list
    }
    @override
    public Object getElementAt(int index)
    {
        return comboBoxItemList.get(index);
    }
    List<String> comboBoxItemList;
    }
    

    Once written what you need you will not to modify the code anymore. And you can use the same model for several different JComboBox also.

    YourModel model = new YourModel("path_to_a_file");
    JComboBox box1 = new JComboBox();
    box1.setModel(model);
    JComboBox box2 = new JComboBox();
    box2.setModel(model);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently building a desktop java application in a very clumsy manner. The application
I am currently building an application using Tomcat, Spring and JAVA. I am using
I'm currently working on a project that is building a java-based desktop application to
I'm a relative newbie to Java and am building an application for my programming
I am currently building a java-servlet-based web application that should offer its service to
So I have this extremely memory-intensive Java application I'm building, which builds a tree
I am currently building a RCP application based on Eclipse. In one of my
Currently I'm building my Java Web Application on Google AppEngine (GAE), but due to
I'm currently building a Java GUI application and I'm about to implement something that
I am currently building some application for iOS. It is actually my second application.

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.