How to declare a Combobox without using a string in its declaration?

How to declare a Combobox without using a string in its declaration?

What i mean to ask is how can i declare a combobox first and initialise the values later?

For example

JComboBox x= new JComboBox(); ... String s={"Alpha","Beta","Gamma"}; ... setSomething.JComboBox(s);

Is it even possible? From all the examples and tutorials so far i haven't found any which tells me how to do this.

Help will be very much appreciated!

View Answers

February 2, 2012 at 8:51 PM

Thanks a lot !!


February 2, 2012 at 4:19 PM

import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class DynamicCombobox {

public static void main(final String args[])throws Exception {
JFrame frame = new JFrame();
frame.setLayout(null);
JLabel lab=new JLabel("Course");
        final JComboBox combo=new JComboBox();
        combo.addItem("--Select--");
        Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           final Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from employee");

           while(rs.next()){
           combo.addItem(rs.getString("name"));
           }

    lab.setBounds(10,10,100,20);
    combo.setBounds(120,10,100,20);

    frame.add(lab);
    frame.add(combo);

    frame.setSize(300,100);
    frame.setVisible(true);
    }
}









Related Tutorials/Questions & Answers:
How to declare a Combobox without using a string in its declaration?
how to reverse a string without changing its place
Advertisements
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
how to convert string to char array in java without using tochararray
How to declare String array in Java?
how to start intergrated webcam of a laptop without calling its exe file using java only - Java Beginners
Java repeat string without using loops
Breaking a string into words without using StringTokenizer
String length without using length() method in java
Java reverse string without using inbuilt functions
Declare string array in Java (one and two dimensional)
How to insert data from a combobox and textbox values into DB using JSP?
How to make addition of two combobox values using jsp and javascript?
print reverse string without api
Jdbc Login Page Validation using Combobox
how to validate the telephone number without using jquery in html with javascript
how to delete a row in sql without using delete command.
How to declare array in Java?
how can i achieve multiple inheritance in java without using inheritance ?
without using built-in functions
how to access the object of one frame on clicking a button without using this keyword
How to declare NSMatrix
how to build a colorful clock in JSP without using Flash.
How to split string in Java using comma?
how to count words in string using java
How to pass and catch HTML parameters to a Java program using REST services?(without using servlet/jsp)
how to use an editable combobox
Without Using Form in Java Script
using tiles without struts
How to make a CRUD without using SQL Server? by just using your GUI? (CRUD = Creating, Register, Update, Delete)
Pagination without using database in php
messages to the screen without using "document.write()"
Array of String using Pointers
Sorting arraylist without using Collection.sort()
Match string using regular expression without Case sensitivity
java code using combobox,radiobutton,checkbox
How to Declare Abstract Class in PHP ?
how to convert xml string to soap request object using axis1.4?
How you can escape a String for HTML using the StringEscapeUtils
How to match a string symbols using the INDEX and the method use Stack
How to match a string using the INDEX and the method use Stack or Queue?
How to Declare fflush() Function in PHP
How can we extract string 'roseindia.net ' from a string http://deepak@roseindia. net using regular expression of php?
How ro convert char into string using recursive function in c#??
Add year to Date without using Calendar in java
how to select second combobox value .
How can I paginate a table which has shown in a div through Ajax in client side without using database
i want code of signing off from a account how its done in jsp and servlet by using either cookies or session
JSPs : Declarations
string palindrom using vbscript?

Ads