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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:00:03+00:00 2026-06-08T19:00:03+00:00

I am currently writing a program in Java that uses a query populated jcombobox.

  • 0

I am currently writing a program in Java that uses a query populated jcombobox. I was wondering if there is a way to have a default selected value when the program executes. My query is a list of languages listed alphabetically, but I am curious if it is posible to have English (which is in the middle of the list) be the default value.

I know that when you manually hard code the values into the jcombobox you can set the default variable as

jcombobox.setSelectedIndex(int anIndex);

or

jcombobox.setSelectedItem(Object anObject);

but I am unsure when a ResultSet loops and populates the jcombobox.

Currently my code is:

languageLabel =new JLabel("Languages:");
rowFour.add(languageLabel,BorderLayout.WEST);//adding to my current panel
langbox = new JComboBox(); 
rowFour.add(langbox,BorderLayout.WEST);
try
 {
     con = DriverManager.getConnection ("jdbc:oracle:thin:@localHost:portNumber:ORCL", "username", "password"); 
     statement = con.createStatement();
 }
catch(SQLException sqle) 
            {
            System.out.println(sqle);    
            }
langbox.removeAllItems();
langbox.addItem("Please Select...");
 try
   {
      ResultSet rs = statement.executeQuery("select language from language order by 1");
      while (rs.next())
            {
                langbox.addItem(rs.getString(1));
                //Thinking that this is where a default value would be located
            }

   }
 catch(Exception e)
  {   
    System.err.println(e);
  }

Thank you for your time.

  • 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-08T19:00:05+00:00Added an answer on June 8, 2026 at 7:00 pm
    ResultSet rs = statement.executeQuery("select language from language order by 1");
    while (rs.next()) {
       langbox.addItem(rs.getString(1));
       //I'm thinking that this is where a default value would be located
       if(rs.getString(1).equals(myDefaultLanguageVariable)) {
          langbox.setSelectedItem(rs.getString(1));
       }
    }
    

    btw: You should clean up that code, its not good that way.

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

Sidebar

Related Questions

I am currently writing a chatroom program in Java. There is a server that
I'm currently writing a java program that requires some Data to run. The data
I'm currently writing a program in Java that I would like to use to
I'm currently writing a Java program that can open .exe programs on my PC,
Currently I am writing a program for an introductory Java class. I have two
I am currently a java newbie of sorts writing a program that is, essentially,
I am currently writing a program using Weka that builds a model (using one
I am writing a program that generates excel reports, currently using the Microsoft.Interop.Excel reference.
I have been writing a small java application (my first!), that does only a
I am currently writing a program that I need to send to a friend

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.