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 and cliuck on some save button . i am able to save it. but when i try to cahnge the value and when i clicked on save unable to save it. how to maKE Jcombox editable after saveing value init.

View Answers

May 30, 2013 at 7:42 PM

hi friend,

Try the following code may, this will be helpful for you.

package net.roseindia.swingExample;

import java.awt.event.*;
import java.sql.*;
import java.util.HashSet;
import java.util.Iterator;

import javax.swing.*;
public class EditableComboBox implements ActionListener{

    String[] petStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig" };
    String petName ="";
    JComboBox petList;
    JButton button;

private void createUI()
    {
        JFrame frame = new JFrame("Editable Combo Box");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
        frame.setLayout(null);      

        JLabel label = new JLabel("Select from list : ");
        button = new JButton("Insert");
        button.addActionListener(this);
        label.setBounds(10, 30, 100, 20);
        button.setBounds(275, 30, 100, 20);
        petList = new JComboBox(petStrings);

        petList.setBounds(110, 30, 150, 30);
        petList.setSelectedIndex(0);         

        frame.add(button);
        frame.add(label);
        frame.add(petList);

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

@Override
public void actionPerformed(ActionEvent e){

    HashSet set = new HashSet();
    if(e.getSource() == button)
    {
        String[] newList = new String[petStrings.length+1];
        petName = (String)petList.getSelectedItem();
        int i = 0;
        while(i < petStrings.length)
        {
            newList[i]= petStrings[i];
            set.add(newList[i]);            
            i++;
        }
        newList[i] = petName;
        set.add(newList[i]);        
        Iterator itr = set.iterator();
        while(itr.hasNext())
        {
            String s = (String) itr.next();         
            if(petName.equals(s))
            {
                addOperation();
            }
        }       
        petList.setEditable(true);
      }
}

 private void addOperation()
 {
    try
    {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:swing");
        String sql = "INSERT INTO PetTable(petName) Values('"+petName+"')";
        Statement st = con.createStatement();
        st.execute(sql);
        JOptionPane.showMessageDialog(null, "Record Added Succesfully.","Record Added",
                JOptionPane.INFORMATION_MESSAGE);
    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, e.getMessage(),"Error",
                JOptionPane.ERROR_MESSAGE);
    }
  }
 public static void main(String args[])
 {
     EditableComboBox gvb = new EditableComboBox();
     gvb.createUI();
 }
}// class closed

Thanks.









Related Tutorials/Questions & Answers:
how to maKE Jcombox editable after saveing value init.
how to maKE Jcombox editable after saveing value init.  i have one... the value and when i clicked on save unable to save it. how to maKE Jcombox editable after saveing value init
JComboBox Insert Edited Value Into Table
JComboBox Insert Edited Value Into Table In this section we will read about how to make JComboBox an editable and then how to insert the new edited value... in to insert an editable value of JComboBox into a table. We will use an Java editor
Advertisements
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 JTree
Editable JTree Nodes        In this section, you will learn  to make JTree editable... the editable mode to " true " through the setEditable() method. The init
how to load value in dropdown list after selecting value from first dropdown list using javascript
how to load value in dropdown list after selecting value from first dropdown list using javascript  how to load value in dropdown list after selecting value from first dropdown list using javascript
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
Get radio button value after submiting page
Get radio button value after submiting page  Radio buttons... , the value of the selected radio button get displayed in that jsp page. <...;input type= "radio" name="radiobuttonn" value= "<%=Countrycodee%>">
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
editable datagrid
editable datagrid  How to create a editable datagrid in jsp,struts1.3,glassfish v2.x application server and database oracle using netbeans6.8 ide.... ThanksADS_TO_REPLACE_2   thanks but i want a editable grid,with the option
how make ID - Ajax
how make ID  how make a ID in eyeball chat
How to make elements invisible ?
How to make elements invisible ?   How to make elements invisible
how to make this pattern???
how to make this pattern???  how to make following pattern in javascript
ModuleNotFoundError: No module named 'sphinxcontrib-editable'
: No module named 'sphinxcontrib-editable' How to remove the ModuleNotFoundError... sphinxcontrib-editable After the installation of sphinxcontrib-editable python...ModuleNotFoundError: No module named 'sphinxcontrib-editable'  Hi
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 make exampage in jsp ?
how to make exampage in jsp ?  how to make a online exam page in jsp and servelet
How to make selectOneMenu scrollable
How to make selectOneMenu scrollable  how to make the selectOneMenu scrollable? I have around 20 values in drop down and i want the scrollable functionality after 5 values. Kindly reply as soon as possible. Thanks Shikha
how to update the value of jslider
how to update the value of jslider  hello, I want to make a audio player but the jslider is not updating help me
how to update the value of jslider
how to update the value of jslider  hello, I want to make a audio player but the jslider is not updating help me
how to update the value of jslider
how to update the value of jslider  hello, I want to make a audio player but the jslider is not updating help me
how to update the value of jslider
how to update the value of jslider  hello, I want to make a audio player but the jslider is not updating help me
how to update the value of jslider
how to update the value of jslider  hello, I want to make a audio player but the jslider is not updating help me
how to make a program on array
how to make a program on array  When you make a program on array that the element will move downward and upward and when you input twice 0 then thats the time that it will not move. pls. give me a formula...tnx
How to make a button of different behaviour?
How to make a button of different behaviour?  Suppose In a jsp page I have a button SAVE with id="btnSave" value="SAVE" and a javascript function... ajaxInsertUpdateData(document.getElementByID("btnSave1").value,......); How to do
ModuleNotFoundError: No module named 'django-content_editable'
: No module named 'django-content_editable' How to remove the ModuleNotFoundError... django-content_editable After the installation of django-content_editable...ModuleNotFoundError: No module named 'django-content_editable'  Hi
How to make a transparent text
How to make a transparent text Learn how to make a transparent... mask tool (T key) and make formatting as looking here. Write Text: Now write your text as you like. I have written here "Text". After writing
how make excel
how make excel  how make excel spreadsheet IN JAVA. please send this code argently   Hello Friend, Try the following code: import java.io.*; import org.apache.poi.hssf.usermodel.HSSFSheet; import
how to make multiple rectangles
how to make multiple rectangles  I,m a beginner , m sorry if the question is really simple i have an array list.I want to print the contents...(JFrame.EXIT_ON_CLOSE); //Set JFrame size setSize(400,400); //Make JFrame
why above code returning the value of squares is 82... even after returning an increnented value of squares... please help me...
why above code returning the value of squares is 82... even after returning an increnented value of squares... please help me...   public class d55 { int squares = 81; public static void main(String
How to make a chain, make a chain, chain
How to make a chain       To learn how to design a chain in the photoshop has become so easy by this example, it has some important instruction to make it so follow
how to make paging with function ?
how to make paging with function ?  how to make paging with function ?   //this page is display.php <?php</p> $con=mysql_connect("localhost","root",""); if(!$con) { die("you can connect please check". mysql
how to make a field left justification
how to make a field left justification  how to make a field left justification.need code.thanks in advance
how to make a label left alignment?
how to make a label left alignment?  how to make a label left alignment
How to make first JSP page?
How to make first JSP page?  Hello, How I can make first JSP page? Thanks
How to make first JSP page?
How to make first JSP page?  Hello, How I can make first JSP page... and add code to it. After adding the code you can run it on the tomcat. Check tutorial: How to make my first JSP page? Thanks
How to make bubbles, make bubbles, bubbles
How to make bubbles      ... to make it easily to draw. New File: First take colored background file.ADS.... ADS_TO_REPLACE_3 Duplicate: Now make duplicate layer and press Ctr
Init Parameter
Init Parameter  How set Init Parameter in servlet
how to make paging with class and ajax
how to make paging with class and ajax  paging with class and ajax
How to make directory in java
Description: This example demonstrate how to create a directory at specified path. Code: import java.io.File; public ... is that it will make a dir at root directory of C drive
display uploaded file option in editable form
display uploaded file option in editable form  how to show the uploaded file in editable mode on the jsp in struts2.0
display uploaded file option in editable form
display uploaded file option in editable form  how to show the uploaded file in editable mode on the jsp in struts2.0
How to make a bone, make a bone, a bone
How to make a bone       This example bone design example, It is very easy. If you are looking for, please follow now. New File: Create a new file.ADS_TO_REPLACE_1
How to make a new List in Java
How to make a new List in Java  Hi, I have to create list object in Java. How to make a new List in Java? Thanks (adsbygoogle = window.adsbygoogle || []).push({});   Hi, The easiest way is to use
how to make multiple choice questions
how to make multiple choice questions  I have to make a multiple choice choice using JSP/Servlets. I created a a session bean for the questions and answers. how to associate group of questions to a user? so each user will have
How to make halo effect
How to make halo effect       Now get ready to learn a simple way to make a halo effect on the picture, follow to make it. Take a picture: Capture any picture to give
how to get radio value
how to get radio value    how to retrive the option value and insert the next table pls give example
How to Make iPhone Window Application
How to Make iPhone Window Application  Hi, For Making iphone window application, what parameters i have to follow or provide example related to iphone window application. Thanks
How to make query and abstraction in Java
How to make query and abstraction in Java  Hi, I read the lessons you have in the sites. They are really useful. However, I could not write codes... PostgreSQL database, and I want to make a query and abstraction for a table. Could
how to make paging with class and ajax
how to make paging with class and ajax  paging with class and ajax... displayLinks($show){ $this->show = $show; // How many links to show..."] == $this->p){ //if p is equal to the current loop value then dont display that value
how to disable submit button after login in jsp
how to disable submit button after login in jsp  Hi, I have... on the back button in browser it stars displaying login page. How to prevent this? how to disable submit button after login in jsp? Thanks   Hi, You can
How to save image after edit in php
How to save image after edit in php  Hello, I have create a simple... successfully but i don't know how to replace orignal image with the effects. please...="220" height="277" name="image1"> <button value="pixastic-desaturate

Ads