Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT 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.
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


raveen
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.
1 Answer(s)      2 years ago
Posted in : Swing AWT


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.


Advertisement
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
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
Advertisements
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
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
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
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 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
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
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 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
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
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
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> <
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
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 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
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
Combobox in HTML
the options in the list. Here is how to make a simple Combobox in HTML: <html>...Combobox in HTML is used to display a drop-down list of some options from...;select> <option value="Select">Select....</option> <option
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
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
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
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
 

 

 

DMCA.com