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



Home Answers Viewqa Swing-AWT how to maKE Jcombox editable after saveing value init.

Have Programming Question? Ask it here!
 
 
 


raveen
how to maKE Jcombox editable after saveing value init.
1 Answer(s)      a year and 8 months ago
Posted in : Swing AWT


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.


Advertisement
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
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
Advertisements
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
Editable JTree
Editable JTree Nodes        In this section, you will learn  to make JTree editable...: This program constructs a JTree that contains editable nodes. Firstly, it defines
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
Init Parameter
Init Parameter  How set Init Parameter in servlet
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...;thanks but i want a editable grid,with the option of modify and delete
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 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
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%>">
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
init method
init method  why init method used in servlet?   The init() method is called only once by the servlet container throughout the life of a servlet. By this init() method the servlet get to know that it has been placed
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
how to make exampage in jsp ?
how to make exampage in jsp ?  how to make a online exam page in jsp and servelet
Access web.xml init parameters
Access web.xml init parameters  How to access web.xml init parameters from java code
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 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
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
Counter in Init() Method
. In this program we are going to make use of the init method of the Servlet interface... which will have the initial value of the counter. The init() method accepts... getInitParameter() method of  the ServletConfig interface to the value of the init
How to make a transparent text
How to make a transparent text Learn how to make a transparent...) and make formatting as looking here. Write Text: Now write your text as you like. I have written here "Text". After writing text make copy (Ctr
difference between init() & init(ServletConfig config)?
difference between init() & init(ServletConfig config)?  I want to know the difference between init() and init(ServletConfig config) methods in GenericServlet
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
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 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
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 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
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 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
How to make bubbles, make bubbles, bubbles
How to make bubbles      ... to make it easily to draw. New File: First take colored background file. Draw... Overlay, use same both settings as given below. Duplicate: Now make
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
how to get radio value
how to get radio value    how to retrive the option value and insert the next table pls give example
Servlet Init method
Servlet Init method  can we capture the form data into the init method of the servlet
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 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. Rounded rectangle
how update JTable after adding a row into database
how update JTable after adding a row into database  J have two... in JTable, and it's OK, but after adding a row into database table does't update. How update JTable after adding a row into database? package djile pak.java
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
init method of ActionServlet and RequestProcessor
init method of ActionServlet and RequestProcessor  hi every when the ActionServlet init() method is executed? please give answer for the above query
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 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
Advertisements
 

 

 

DMCA.com