Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default Stoping repeated entries in JComboBox

    Hi everyone,
    I am coding a program in which JComboBox displays the name of every different computer which sends it connection request.But my program enters every name in JComboBox from which it accepts request despite it is already present in the box. Please help , I have tried everything I can do.
    Thanks in advance
    Code snippet :
    Java Code:
    String hostarray[] = new String[50];
    	public static int i=0;
     
     public  void addHost(String host)
    	  {
    	  check = true;
    	  int j;
    	 for( j=0; !hostarray[j].equals(null);j++)
    		  {
                  if(hostarray[j].equals(host))
    			  { 
    			  check =false;
    			  break;}			  
    	      } 
          if(check)
    		  {
    		    hostarray[i]=host;             
                  UserInterface.jComboBox1.addItem(host);
                  UserInterface.jComboBox2.addItem(host);
                  UserInterface.jComboBox3.addItem(host);
                  UserInterface.jComboBox4.addItem(host);
                  UserInterface.jComboBox5.addItem(host);
                  UserInterface.jComboBox6.addItem(host);
    		  }
           i++;
    	System.out.println("Value of i "+i);	   
        }

  2. #2
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    449
    Rep Power
    6

    Default

    Combobox control already has a method remove().
    If your new object is already in combobox,you can use remove method
    Mak
    (Living @ Virtual World)

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,238
    Rep Power
    19

    Default

    Just another cross poster.
    Swing - Stoping repeated entries in JComboBox

    db

  4. #4
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default

    Sorry for the cross poster but I needed the solution urgently in my project thats why i repeat.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    cross-posting will often have the opposite effect of what you desire: many will avoid helping you if you do this, without at least posting the links. So my advice is if you feel you must do this, at least post links from each cross-post to another. Good luck.

  6. #6
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Question

    Thanks for your suggestion and i will seriously follow it. But what about my solution, can anyone please solve the problem.

Similar Threads

  1. Remove repeated code
    By FraggleBoDiddly in forum New To Java
    Replies: 6
    Last Post: 10-26-2008, 02:28 PM
  2. Not able to delete MSSql database table entries
    By wickedrahul9 in forum Advanced Java
    Replies: 3
    Last Post: 10-17-2008, 12:14 PM
  3. JCombobox
    By daniel50096230 in forum NetBeans
    Replies: 1
    Last Post: 09-21-2008, 12:23 PM
  4. Replies: 2
    Last Post: 02-16-2008, 08:52 PM
  5. jcombobox
    By Freddie in forum AWT / Swing
    Replies: 4
    Last Post: 05-11-2007, 12:48 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
  •