Results 1 to 12 of 12
  1. #1
    bhaskaranbe is offline Member
    Join Date
    Jun 2015
    Posts
    7
    Rep Power
    0

    Post Multimap values in combobox using javafx

    I want to create two combo-box one contain Multimap keys and another combobox contain Multimap values. example my Multilmap values are:

    Hashtable<String, String> hm = new Hashtable<String, String>();

    keys =Student Name and Values=topper in subjects

    example: {Ananth=[English, Maths], Karan=[Computer Science, Physics]}

    First combo box should display name: Ananth and karan

    if first combo box select value as "Ananth" the second combobox should display the values "English, Maths"
    if first combo box select value as "Karan" the second combobox should display the values "Computer Science, Physics"

    The first combobox i did:

    ComboBox <String> student=new ComboBox<String>();
    student.getItems().addAll(multimap.keySet());

    please let me know the logic or code for doing 2nd combox box.

    Thanks,
    Bhaskaran

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Multimap values in combobox using javafx

    There's no class named Multimap in the standard Java API. For the use case you describe, I would use a Map<String, List<String>>

    The logic would then entail responding to a change in the first combo selection to retrieve the List mapped to its selected value, and using that List to (re)populate the second combo.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Multimap values in combobox using javafx

    Quote Originally Posted by DarrylBurke View Post
    For the use case you describe, I would use a Map<String, List<String>>
    Or, since there won't be duplicated subjects, a Map<String, Set<String>>

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Multimap values in combobox using javafx

    I'm guessing a 'multimap' is used because names can actually exist multiple times as a key? And as such the multimap being referred to here is from Apache commons-collections?

    MultiMap (Commons Collections 3.2.1 API)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Multimap values in combobox using javafx

    If that's so, this should be in the Apache Commons section.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    bhaskaranbe is offline Member
    Join Date
    Jun 2015
    Posts
    7
    Rep Power
    0

    Default Re: Multimap values in combobox using javafx

    I used "google-collections-1.0-rc2.jar" and "common-collections-tree-1.0.5-sources.jar" for ListMultimap<String, String> multimap = ArrayListMultimap.create();

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Multimap values in combobox using javafx

    Quote Originally Posted by bhaskaranbe View Post
    I used "google-collections-1.0-rc2.jar" and "common-collections-tree-1.0.5-sources.jar"
    Sorry, can't help you with that.

    Do you have a reason for not working with the standard JDK classes?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    bhaskaranbe is offline Member
    Join Date
    Jun 2015
    Posts
    7
    Rep Power
    0

    Default Re: Multimap values in combobox using javafx

    if i use "LinkedHashMap<String,List<String>> mp=new LinkedHashMap<String, List<String>>();" means am getting the Linked hasmap as: {Ananth=[Maths], Karan=[Physics]}


    My input data is xml file:

    <?xml version="1.0"?>
    <StudyDetails>
    <Student id="Ananth">
    <SubjectName>English</SubjectName>
    </CLIENT>
    <Strudent id="Ananth">
    <SubjectName>Maths</SubjectName>
    </CLIENT>
    <CLIENT id="Karan">
    <SubjectName>Computer Science</SubjectName>
    </CLIENT>
    <CLIENT id="Seno">
    <SubjectName>Physics</SubjectName>
    </CLIENT>
    </StudyDetails>

    am reading the values from the xml file and wants to create 2 combobox for "id" and "subjectName",

    i want to create one combobox for id, and another combobox for "text content" of subjectname.

    example: if i click first combobox values as "Ananth", the second combobox should display the value as "English" and "Maths" (two values)


    am able to create first combobox which contains "Ananth" , "karan" as values, but am not sure how to create 2nd combobox. Please let me know how to do that.
    Last edited by bhaskaranbe; 06-19-2015 at 01:35 PM.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Multimap values in combobox using javafx

    What is wrong with Darryl's previous suggestion of a Map<String, Set<String>>?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Multimap values in combobox using javafx

    The focus is too much on the datastructure used I think; if I read between the lines the actual question is "How do I populate the second combobox when I make a selection in the first combobox".
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    bhaskaranbe is offline Member
    Join Date
    Jun 2015
    Posts
    7
    Rep Power
    0

    Default How do I populate the second combobox when I make a selection in the first combobox

    Quote Originally Posted by gimbal2 View Post
    The focus is too much on the datastructure used I think; if I read between the lines the actual question is "How do I populate the second combobox when I make a selection in the first combobox".
    Yes, @gambal,
    Please let me know how to do that

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Multimap values in combobox using javafx

    Do you know how to add a listener to respond to a change of selection in a combo?
    ComboBoxBase (JavaFX 8)

    And don't double post. Your other thread has been closed.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Javafx - ComboBox
    By ghansham in forum JavaFX
    Replies: 3
    Last Post: 07-06-2013, 04:16 PM
  2. No values from database in Combobox
    By aborgeld in forum New To Java
    Replies: 3
    Last Post: 01-01-2011, 08:38 PM
  3. Statistic calculs in a MultiMap
    By Posthume82 in forum New To Java
    Replies: 2
    Last Post: 07-15-2010, 03:47 PM
  4. Replies: 0
    Last Post: 05-13-2009, 03:55 PM
  5. List in Combobox database values
    By Glouze in forum Advanced Java
    Replies: 1
    Last Post: 01-16-2009, 05:26 PM

Tags for this Thread

Posting Permissions

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