how to use an editable combobox

Ads
 

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 should appear in the list.

View Answers

June 20, 2012 at 11:44 AM

Here is an example of Editable JCombobox.

import java.sql.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
class  EditableComboBox{

    public static void main(String[] args) throws Exception{
        JFrame f=new JFrame();
        f.setLayout(null);
        JLabel lab=new JLabel("Select");
        final JComboBox combo=new JComboBox();
        combo.addItem("Nano");
        combo.addItem("Alto");
        combo.addItem("Swift");
        combo.addItem("WagonR");
        combo.addItem("Scorpio");

        ActionListener actionListener = new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        ItemSelectable is = (ItemSelectable)actionEvent.getSource();
        String name=selectedString(is);
        System.out.println("Selected: " + name);
        }
    };
       combo.addActionListener(actionListener);
       combo.setEditable(true);
        lab.setBounds(20,20,100,20);
        combo.setBounds(120,20,80,20);
        f.add(lab);
        f.add(combo);

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

For more information, visit the following link:

http://www.roseindia.net/java/example/java/swing/AddRemoveItemFromCombo.shtml

Ads









Related Tutorials/Questions & Answers:
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
editable combobox method selection
editable combobox method selection  how to make an editable combobox that shows nothing initially but as a key is pressed it pops up and selects an item starting with that letter, subsequent keys would keep sorting from the list
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 can i display a editable result of form?
how can i display a editable result of form?  how can i display a editable result of form? i know how to display form result but the result... show the result but i can not modify the result. how can i display modifyable
how to maKE Jcombox editable after saveing value init.
how to maKE Jcombox editable after saveing value init.  i have one JCombobox with 2 values"y", "N".when i selecting some value from dropdown... the value and when i clicked on save unable to save it. how to maKE Jcombox editable
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 to use Servlet and Ajax?
How to use Servlet and Ajax?  How to use Servlet and Ajax
HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE
HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE ... createuser.jsp. There am loading this Rolename into combobox. My question is how to get Roleid in textbox when i select Role_name from combobox in a same
How to use AT Commands with J2ME?
How to use AT Commands with J2ME?  How to use AT Commands with J2ME? Thank you for your answer
how to use calender in php
how to use calender in php  how to put calender in php
how to use mouse pressed
how to use mouse pressed   to action mouse clicked
how to use button in array
how to use button in array  plz tell me how to code for button in array
how to use JOptionPane.YES_NO_OPTION
how to use JOptionPane.YES_NO_OPTION  As i said earliar i am making... logging out finally.. i also thinking how to use the input (yes or no ) given... dialog should appear which ask for yes or no . PROBLEM is i dont know how
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 examples and tutorials so far i haven't found any which tells me how to do
how to use setAttribute
how to use setAttribute  how to get following codes using setAttributes in java??? Employee xlink:type="extended" xlink:show="new" xlink:actuate="onRequest
How to use dojoscript with jsf?
How to use dojoscript with jsf?  Hi all , am new to jsf. can anyone help me out in using dojo script frame work with jsf. how to integrate dojo into jsf. Thanks in advance
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?  <html> <h2>ComboBox</h2> <script language="javascript"> var arr
How to use ajax in jsp?
How to use ajax in jsp?  Hi, How i can access the server-side data in JSP using the Ajax? Thanks   Hi, You can use the Ajax code to access the server side data from JSP page. Check the tutorial Combo Box Using Ajax
how to use jstl tags?
how to use jstl tags?  I installed jstl jar in my libraries. I got the following error in console screen. I need the solution to resolve this uri in web.xml. please help me.......... "The absolute cannot be resolved
How to use between in mysql.
How to use between in mysql.  I want to display records inbetween two dates and also want to use where condition( like and deptname='Pediatry Department').      Syntax: SELECT column_name(s) FROM table_name
How to use Apache POI?
How to use Apache POI?  Can anyone tell me how to use Apache POI??I went through http://poi.apache.org/ but cannot understand anything.I don't know how to implement.Please help me out.   Download zip file from
How to use bytes
How to use bytes  I have saved my project and uploaded the picture. But when i want to view the picture, there was no picture. I used the method...(rs.getBytes("employeephoto")); How to get the correct answer to view the picture by using
Editable Html
Editable Html  i have editable html table with following elements textbox(n),checkbox(n),sno,dropdownlist..this elements are generated in runtime... how to take the values from the table and insert into database.please gimme some
how to use image tag in jsp
how to use image tag in jsp  How to use image tag in JSP
How to use Hibernate get sessionfactory?
How to use Hibernate get sessionfactory?  Hi, How to use hibernate get sessionfactory? Thanks
how to use marathi font in swing?
how to use marathi font in swing?  I want to use marathi language on labels,buttons
How to use contentType Attribute in JSP?
How to use contentType Attribute in JSP?  Hi, I am learning JSP and now trying to use the contentType Attribute in JSP. tell me how to use the contentType Attribute in JSP? Thanks
How to use session in struts 1.3
How to use session in struts 1.3  i want to know how to use session in Struts specially in logIn authentication
how to use group by in nested query
how to use group by in nested query  Hai, How to use group by clause in nested query select statement in subquery i am having where clause.please help me.thanks in advance
How to use the PHP filetype() Function
How to use the PHP filetype() Function  Hi, What is the use of filetype() Function in php programming. Can anyone give any online example of the PHP filetype() Function. Thanks
How to create and use Array in Java?
How to create and use Array in Java?  Hi, How to create and use Array in Java? Write program to construct and use the array. Thanks   Hi, You can initialize the int array in following way: int num[] = new int[10

Ads