Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Trying to sort a collection after removing an item in GUI

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Trying to sort a collection after removing an item in GUI

    Hello, I am trying to get my program to remove and item from my collection and then move all the remaining items back together (removing the space from the removed item). My items are displayed through a GUI application as columns. My problem is once I remove the item my program leaves a space. I need it to move the remaining items to the right of the removed item a spot to the left to delete the space. I know it has something to do with making a new array that is a size smaller and displaying that, but I am having trouble displaying the new array.

    	/*
    	 * Method is used to remove items
    	 */
    	public void remove() {
    		if ((newArray != null) && (size > 0) &&
    					(itemSelected > EMPTY) && (itemSelected < size)) {
    		for (int i = itemSelected + 1; i < size; i++)
    			newArray[i - 1] = newArray[i];
    			size--;
    		}
    		itemSelected = EMPTY;
    	}

    	// This method removes an item
    	public void removeAction() {
    		myCollection.reset(selectedItem);
    		myCollection.remove();
    		selectedItem=null;
    		repaint();		
    		}


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Trying to sort a collection after removing an item in GUI

    Sorting a Collection After Removing an Item

    Duplicate post
    Improving the world one idiot at a time!

Similar Threads

  1. display item for item selected in combobox
    By cisco.nat in forum AWT / Java Swing
    Replies: 1
    Last Post: June 20th, 2013, 07:12 AM
  2. Problem with Collection sort
    By bhk in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 30th, 2013, 09:33 AM
  3. Help..Simple GUI needs help,can not sort out these red lines..
    By zhen1606 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 23rd, 2012, 09:06 AM
  4. Collection.sort problem
    By Minken in forum What's Wrong With My Code?
    Replies: 12
    Last Post: September 21st, 2010, 06:24 PM
  5. drag item or insert item into new Jlabel in JPanel
    By qaromi in forum AWT / Java Swing
    Replies: 5
    Last Post: July 6th, 2010, 07:37 PM