Results 1 to 2 of 2
  1. #1
    pra.deep is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Post How at save list in Jcombobox...

    Hi.. everyone..i have used the following codes....the item is added to the current list but while compiling next time the item is not displayed in list of items... how to add item to combobox ...
    Java Code:
    import java.awt.*;
    import java.sql.*;
    import java.awt.event.*;
    import javax.swing.*;
            
    public class Item extends Frame implements ActionListener{        
            
            
    JComboBox dep,type,supp;
    Button save,back,clr,exit;
    String s4,s1;
         TextField icode;
         Label l1;
    public Item()
    {
           super("ITEM");
      setSize(450,500);
        setLayout(null);
        setBackground(new java.awt.Color(180, 180, 180));
        l1=new Label("ITEMNAME"); 
        icode=new TextField();
        
        
      String su[]={"item1"," iem2","item3"  };
              
          supp=new  JComboBox(su);   
           save= new Button("SAVE");
           back= new Button("BACK");
            clr= new Button("CLEAR");
           exit= new Button("EXIT");
          l1.setBounds(20,60,100,60);
          icode.setBounds(150,70,120,30);
          supp.setBounds(20,130,210,30);
        save.setBounds(290,80,100,40);
        back.setBounds(290,140,100,40);
            clr.setBounds(290,200,100,40);
            exit.setBounds(290,260,100,40);
        
        save.addActionListener(this);
        back.addActionListener(this);
        clr.addActionListener(this);
        exit.addActionListener(this);
        
       add(l1);
       add(icode);
       add(supp);
       add(save);
       add(back);
       add(clr);
       add(exit);
       
           
         setVisible(true);   
           
           
           
    }
    
    
    public void actionPerformed(ActionEvent ae)
    {
     if(ae.getSource()==save)
    {
    s1=icode.getText();
    supp.insertItemAt(s1, 0);
      
     JOptionPane.showMessageDialog(this,new String("ITEM Saved"));
    
      
     
    } 
    
    if(ae.getSource()==back)
    {
    this.hide();
    Main st=new Main();
    }
     if(ae.getSource()==clr)
    { 
    
    }
     if(ae.getSource()==exit)
    {
    System.exit(0);
    } 
    
     
    }
    public static void main(String args[])
    {
     Item gi=new Item();
    }
    }

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default

    Well, the first think you need to do is determine if you want to create an AWT or Swing application. I would suggest using Swing since thats what is current. Swing components have "J" in the name (JButton, JFrame...). Next you read the Swing tutorial which has a section on "How to Use Combo Boxes" which contains a working example.

Similar Threads

  1. How can i save the data Internally(auto save)
    By Rama Koti Reddy in forum AWT / Swing
    Replies: 2
    Last Post: 11-01-2010, 08:31 PM
  2. Save PolygonLinked list in Notepad.txt
    By cassysumandak in forum New To Java
    Replies: 3
    Last Post: 10-01-2009, 09:15 AM
  3. how to save added items in jcombobox
    By kwink in forum AWT / Swing
    Replies: 2
    Last Post: 03-22-2009, 06:03 PM
  4. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 08:53 PM
  5. JComboBox and drop-down list.....HELP!!!!!
    By Anna in forum AWT / Swing
    Replies: 1
    Last Post: 06-18-2008, 05:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •