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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


raveen
how to maKE Jcombox editable after saveing value init.
1 Answer(s)      a year and 9 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 to make this pattern???
how to make this pattern???  how to make following pattern in javascript
How to make elements invisible ?
How to make elements invisible ?   How to make elements invisible
how make ID - Ajax
how make ID  how make a ID in eyeball chat
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
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
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
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 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
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
 

 

 

DMCA.com