i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox.

i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox.

i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox.

View Answers

December 18, 2012 at 12:11 PM

Here is an example that shows the selected value from the jcombobox to textfield.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class  SelectComboboxValue{

    public static void main(String[] args) throws Exception{
        JFrame f=new JFrame();
        f.setLayout(null);
        JLabel lab=new JLabel("Select Programming Language: ");
        final JComboBox combo=new JComboBox();
        final JTextField text=new JTextField(20);
        combo.addItem("--Select--");
           combo.addItem("Java");
           combo.addItem("C/C++");
           combo.addItem(".NET");
           combo.addItem("Perl");


        ActionListener actionListener = new ActionListener(){
        public void actionPerformed(ActionEvent actionEvent) {
        ItemSelectable is = (ItemSelectable)actionEvent.getSource();
        String st=selectedString(is);
        text.setText(st);
        //JOptionPane.showMessageDialog(null,"You have Selected: " + name);
        }
    };
       combo.addActionListener(actionListener);
        lab.setBounds(20,20,200,20);
        combo.setBounds(200,20,80,20);
        text.setBounds(280,20,100,20);
        f.add(lab);
        f.add(combo);
        f.add(text);

        f.setVisible(true);
        f.setSize(400,120);
    }
    static private String selectedString(ItemSelectable is) {
    Object selected[] = is.getSelectedObjects();
    return ((selected.length == 0) ? "null" : (String)selected[0]);
  } 
}









Related Tutorials/Questions & Answers:
issue on jcombobox
issue on jcombobox  i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox.only few values in the combobox need this functionality. need
I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid.
I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid.  I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid
Advertisements
how to select second combobox value .
how to select second combobox value .  I requirement is , i have two combo box, i am selected first combo box value then automatically second combo box value show ,But this both combo box value i retrieves in database. please
How to make addition of two combobox values using jsp and javascript?
addition of two combobox values using jsp and javascript  How to make addition of two combobox values using jsp and javascript?  <...++) { var option = document.createElement("option"); option.setAttribute('value',i+1
Java swing: get selected value from combobox
Java swing: get selected value from combobox In this tutorial, you will learn how to get selected value from combobox. The combobox provides the list... of programming languages to the combobox using addItem() of JComboBox class. We have
I am not able to display the selected value of my combobox
;/option>"; $select.="<option name='unitcode' value=\"".$myrow['$i...I am not able to display the selected value of my combobox   <?php echo "<select name=\"hello\">\n"; echo "<option value=\"NULL\">
How to insert data from a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB:student; @table:stu_info; Combobox values:(class1,class2,class3); textbox1
how I do select from select in hql
how I do select from select in hql  select RN from ( select rownum RN, dbid from ( select * from profile p where type = 1912 and name like... doesn't work select RN from ( select rownum RN, DBId from ( select distinct p
values in combobox - Java Beginners
values in combobox  how to fill values in combo box i.e. select tag...: ComboBox var arr = new Array(); arr[0] = new Array("-select-"); arr[1...; for (var i=0;i
Passing values in ComboBox from XML file
Passing values in ComboBox from XML file In this tutorial we are going to know how we can pass a values in ComboBox by using XML.  This example... the data from the XML file and insert it into the ComboBox. To make a program over
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
how to retrieve data from database using combobox value without using request.getParameter in jsp  Answer pl
how to use an editable combobox
how to use an editable combobox   Hello Everyone!!!!!!!! I have a jcombo box with certain values and i want to use it as an editable that means when user will type something in combobox, according to that text only matching item
Combobox jsp from 0 to 10
Combobox jsp from 0 to 10  Hi guys please help me to write a very easy program using jsp to display value in combobox from 0 to 10. How to write...;% for(int i=0;i<=10;i++){ %> <option value="<%=i%>"><%=i%><
How to display data fom MySQL DataBase-table in to JSP file by submitting a value in combobox.
a value in combobox.   I have the same problem.plz help me. I have MySQL... have to display the Nodename and packageno. i.e.,select nodename,packageno from...; Values(crs,cs 4.0,xxx), Values(sdp,cs 5.0,yyy), Values(air,cs 6.0,zzz), i want
combobox
combobox  In dashboar.jsp form, When i click employee id value... stored combo box values from database. can u pls tell me the proceduer to get...=con.createStatement(); ResultSet rs=st.executeQuery("select * from
How to Connect J ComboBox with Databse - Java Beginners
How to Connect J ComboBox with Databse  How to Connect J ComboBox with Databse  Hi Friend, Do you want to get JComboBox values from database?Please clarify this. Thanks
easy way to make a JCombobox look like a JTextField?
easy way to make a JCombobox look like a JTextField?  Is there a good(and easy) way to make a JCombobox look like a JTextField? By this I mean there should not be a dropdown button, but when the user enters something it should
combobox
combobox  Hi, i have one combo Box with 5 options and one Other option also there,when i select a other i need to get a new text box for entering user option and when click on submit it should save on same field in database
combobox
combobox  i have three tables in database country,state and city... depends on state i have implmnt dis code and it work propely bt problem is the field...;option value=''>select country</option> <
combobox
combobox  i have three tables in database country,state and city... depends on state i have implmnt dis code and it work propely bt problem is the field...;option value=''>select country</option> <
I have to retrieve these data from the field table
as single values like chennai as one value, trichy as one value. and i have...I have to retrieve these data from the field table  Hi. I have... chennai,trichy,kanchipuram for a single record. I have to retrieve these data from
Database values in JComboBox
Database values in JComboBox In this section, you will learn how to display values in JComboBox from database. For this, we have allowed the user to enter any character as a key in the textbox .Based on this key value, the results from
Java Swing dynamic Combobox
Java Swing dynamic Combobox In this section, you will learn how to display the data in one combobox related to another combobox. For this, we have created two combo boxes. In the first combobox, we have added four items. When the user
fill combobox at runtime jsp
fill combobox at runtime jsp  i have 1 combobox in jsp which is filled with value from sql db on load of form <% Class.forName... another combobox below it, i want it to be filled on the basis of selected value
i want to select a multiple value of check box by using onclick or onchange event without using from submission
i want to select a multiple value of check box by using onclick or onchange event without using from submission   i have 4 check box name 1)profile...)1000-1500 3)1500-2000 4)2000-2500 when i am selecting first value of checkbox
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Combobox in HTML
the options in the list.ADS_TO_REPLACE_1 Here is how to make a simple Combobox...Combobox in HTML is used to display a drop-down list of some options from...; <select> <option value="Select">Select....</option>
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
i want validation for one text field and text area,email,combobox, in that email will validte by useing regular expressions?
i want validation for one text field and text area,email,combobox, in that email will validte by useing regular expressions?  i want validation for one text field and text area,email,combobox, in that email will validte by useing
HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE
is how to get Roleid in textbox when i select Role_name from combobox in a same...HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE ... Roleid and Role_name. and values are Roleid Role_name 1
how to make employee i card
how to make employee i card  hello friends can anyone help me.. I have to make a project to make Identity card for employees...but i am facing..."); Statement stmt=con.createStatement(); String strQuery = "select * from data
how to store multiple values from drop down in database where i am using java struts 1.3
how to store multiple values from drop down in database where i am using java... where i have to select multiple keyskills. but it is taking only one valuee.. i... is displaying.. i need code in java so that it takes multiple values
JComboBox
JComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according
jComboBox
jComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according
how to insert the selected item of combobox in mysql - XML
how to insert the selected item of combobox in mysql  hi, i have to insert the selected item from combobox into MYSQL database.pls provide... of combobox in mxml.how to insert selecteditem in database. pls suggest me i have
comboBox validation
comboBox validation  dear sir. i want to know . how to validate radio button in struts using xml validation. thanks
Non-edit Combobox with auto fill - Swing AWT
Non-edit Combobox with auto fill  Hi, I have a non-edit...-editable mode of JCombobox, For ex: If user type "Ch" JCombobox should select "Charls", If user type "Chi", JCombobox should select "Chim". I tried to catch
Display JList value selected from the JOptionPane
Display JList value selected from the JOptionPane In this section, we are going to select the particular value from the JOptionPane combobox and displayed that value in the JList. For this purpose, we have created a button and JList
Combobox program - Java Beginners
"); JComboBox jc=new JComboBox(); jc.addItem("Select"); jc.addItem("MCA... in combobox a new text box have to open beside that combo box..  Hi...=new JComboBox(); jc.addItem("Select"); jc.addItem("MCA"); jc.addItem("MBA
how I make the numbers in descending order ?
how I make the numbers in descending order ?   public class Quiz1...]+" "); } } thanks how I make the numbers in descending order ?   ...; number.length; i++){ System.out.print("Insert value number"+(i+1
editable combobox method selection
editable combobox method selection  how to make an editable combobox... an item starting with that letter, subsequent keys would keep sorting from the list. just like we get when we select method for an object in an IDE
how to select the row value that was retrived from the database ?
how to select the row value that was retrived from the database ?  I... in the page in which i am getting all the data from the database has an another select option as : Approve, Disapprove & Pending. Now if i select any option
how to select the row value that was retrived from the database ?
how to select the row value that was retrived from the database ?  I... in the page in which i am getting all the data from the database has an another select option as : Approve, Disapprove & Pending. Now if i select any option
how can i make monthly register ?
how can i make monthly register ?  how can i make monthly register ? iam using jdeveloper
pbml in inserting selected item from combobox into mysql - XML
pbml in inserting selected item from combobox into mysql  hi, i have to insert the selected item from combobox into MYSQL database.pls provide... of combobox in mxml.how to insert selecteditem in database. pls suggest me i have
I have problem in my Project
was click on edit he is display all data from database but i want to select any row and than press enter than all data will select autometic in JTextField how please...I have problem in my Project  Dear Sir, i have

Ads