Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By Fubarable

Thread: JCombo Box and Hashmap confusion

  1. #1
    gsb1bee is offline Member
    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0

    Default JCombo Box and Hashmap confusion

    Hi, I am trying to create JCombo Box for sorting images by name, title, most recent etc.

    First I created Hashmap below is the code which does the sorting orders.

    My question is how do I connect this sorting with JComboBox drop down menu. Please can you make this work for me by writing the code.

    Java Code:
    import java.util.*;         // For collections.
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    //  *************************************************************************
    /** An application for handling a simple photo database.
      * 
    //  *************************************************************************
    
    public class RunPhotoApp2 extends JFrame implements ActionListener
    {
        
    
       
        /** Creates a simple photo database and displays simple query results.
         *  @param args Command line arguments (ignored).
         */
        public static void main(String[] args)
        {
            // Create the two tables.
            Map<Long,Photo> photos = new HashMap<Long,Photo>();
            photos.put(3609624150L,new Photo("Female Rabid Wolf Spider","7539598@N04","08062009"));
            photos.put(3596720576L,new Photo("Head of Long Legged Fly", "7539598@N04","04062009"));
            photos.put(4336541668L,new Photo("Bronco",                 "55186440@N00","06022010"));
            photos.put(4162213878L,new Photo("P1050942v01-frost-rose", "14884524@N08","05122009"));
            
            Map<String,Contributor> contributors = new HashMap<String,Contributor>();
            contributors.put("7539598@N04",  new Contributor("Thomas Shahan",230));
            contributors.put("55186440@N00", new Contributor("Brian DeMeester",610));
            contributors.put("14884524@N08", new Contributor("Kilarin",104));
            
            // Create a sorted list of photos.
            TreeSet<Photo> sortedPhotos = new TreeSet<Photo>(photos.values());
                                              
            // Do a query and display the results.
            for (Photo photo : sortedPhotos)
            {
                Contributor contributor = contributors.get(photo.getContributorID());
                System.out.println(photo.getTitle()+" by "+contributor.getName());
            }                              
            
        }  
    }
    Last edited by JosAH; 12-10-2011 at 07:48 AM. Reason: added [code] ... [/code] tags

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

    Default Re: JCombo Box and Hashmap confusion

    Quote Originally Posted by gsb1bee View Post
    Please can you make this work for me by writing the code.
    ...
    Please have a seat while we whip this up for you; it shouldn't take too long. Also, feel free to help yourself to some coffee and doughnuts while you wait.
    DarrylBurke likes this.

Similar Threads

  1. AutoSuggest JCombo box
    By vsmilejay in forum AWT / Swing
    Replies: 2
    Last Post: 09-03-2010, 06:34 AM
  2. JCombo Box selection index?
    By Prajin in forum AWT / Swing
    Replies: 3
    Last Post: 07-19-2010, 08:12 PM
  3. jcombo in jtable
    By anilkumar_vist in forum Advanced Java
    Replies: 0
    Last Post: 12-12-2009, 06:47 AM
  4. Sort jcombo in jtable
    By anilkumar_vist in forum Advanced Java
    Replies: 1
    Last Post: 12-11-2009, 05:23 PM
  5. Replies: 7
    Last Post: 12-08-2009, 07:17 PM

Posting Permissions

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