Results 1 to 4 of 4
  1. #1
    Commodus is offline Member
    Join Date
    Jan 2017
    Posts
    2
    Rep Power
    0

    Default How can I change the Jlist source clicking different jList item?

    How can I change the Jlist source clicking different jList item?-jlist.png
    I've three Jlists and every Jlist item create a new jlist source for the next jlist.
    For example first jlist have three items which are "A" ,"B" ,"C".When I clicked A ,the next list show 1,2,3,4,5. and when I clicked B the same next list show 7,8,9.I need these lists which work on this logic.
    Thanks for helps.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: How can I change the Jlist source clicking different jList item?

    I don't believe the single interval, etc has anything to do with what you want. That is basically whether you want to chose one element, a range of elements, or two disjoint ranges of elements. As I understand it you want to select A in the first pane and have it populate a list of choices in the second pane. Then when you chose an element in the second it populates a selection in the third pane.

    So if I were doing this, I would simply set up three separate JLists and lay them out horizontally and then populate each model appropriately. Also note that depending on your requirements, it might make sense to allow an interval selection of the last pane. To read about JLists, check out this link

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Commodus is offline Member
    Join Date
    Jan 2017
    Posts
    2
    Rep Power
    0

    Default Re: How can I change the Jlist source clicking different jList item?

    Quote Originally Posted by jim829 View Post
    I don't believe the single interval, etc has anything to do with what you want. That is basically whether you want to chose one element, a range of elements, or two disjoint ranges of elements. As I understand it you want to select A in the first pane and have it populate a list of choices in the second pane. Then when you chose an element in the second it populates a selection in the third pane.

    So if I were doing this, I would simply set up three separate JLists and lay them out horizontally and then populate each model appropriately. Also note that depending on your requirements, it might make sense to allow an interval selection of the last pane. To read about JLists, check out this link

    Regards,
    Jim
    Hi, thanks for your comment, I have low fidelity of my UI, I put part of it down, that's exactly what I want.
    How can I change the Jlist source clicking different jList item?-jlistlist.png

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,983
    Rep Power
    8

    Default Re: How can I change the Jlist source clicking different jList item?

    You need to add a ListSelectionListener, so you can react on selection changes. This of looks like this:
    Java Code:
            JList<String> list1 = new JList<>();
            list1.addListSelectionListener(new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    if (!e.getValueIsAdjusting()) {
                        int selectedIndex = e.getLastIndex();
                        //update second JList here 
                    }
                }
            });
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Having issues with adding an item to JList.
    By Vinx in forum AWT / Swing
    Replies: 5
    Last Post: 08-08-2012, 06:16 PM
  2. Having issues with adding an item to JList.
    By Vinx in forum New To Java
    Replies: 0
    Last Post: 08-08-2012, 04:18 PM
  3. JList item text does not truncate when it's HTML
    By edsporty in forum New To Java
    Replies: 1
    Last Post: 03-02-2011, 08:09 PM
  4. Add JList item from resultset
    By mine0926 in forum NetBeans
    Replies: 1
    Last Post: 06-17-2010, 09:47 AM
  5. Clicking Items inside of a JList
    By hunterbdb in forum AWT / Swing
    Replies: 9
    Last Post: 10-21-2009, 06:50 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
  •