Results 1 to 15 of 15
  1. #1
    dbstudio is offline Member
    Join Date
    Sep 2009
    Posts
    5
    Rep Power
    0

    Default Customizing a JList?

    Hello Java Forums

    Thanks for a real nice forum, I'm looking forward to spend alot of time in here, browsing and helping others.

    But I stumbled upon a problem with JList/ListModel/ListCellRenderers.

    I want a jlist with grouped sorted view:


    A -> Non selectable custom header for all entries beginning with an 'A'
    Abraham
    Abel
    Abedeliciouse
    B -> Non selectable custom header for all entries beginning with a 'B'
    Bach
    Beethoven
    Beetlejuice

    And so forth

    I already got the solution to get a non-selectable header but then the problem is I will get a header above all the A's like this:
    A
    Abrahavm
    A
    Abel
    A
    Abedeliciouse
    B
    Bach
    B
    Beethoven
    B
    Beetlejuice

    and so forth

    Can a kind soul help me in the right direction as I guess I am not far from the solution.

    Thanks in advance

    David Bundgaard

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

    Default

    I don't know the answer for sure, but I don't think a custom renderer is the solution since renderers are for changing the display of each cell. Perhaps you'll get more mileage by creating a custom model that adds and removes non-selectable elements when you add or remove elements from it (i.e., it will add a non-selectable "F" item if you add the first selectable element that starts with "F", and likewise will remove this "F" header element if after a removal there are no more elements that start with "F".

  3. #3
    devunion is offline Member
    Join Date
    Jun 2008
    Posts
    56
    Rep Power
    0

    Default

    I think that will be quite difficult to custmize JList as you wish. Take a look also at BasicListUI class (paint method and etc). So, you can use your own model with custom selection model and custom painting.

    Another way is to design necessary component from other Swing controls. Non selectable custom header can be JLabel, grouped elements can be placed in JList. So, one label and one list for each button.
    Try Controls4J - Advanced Swing Components.

  4. #4
    Michael Dunn is offline Member
    Join Date
    Jul 2008
    Posts
    62
    Rep Power
    0

    Default

    It's not that hard to do.

    create a class for your items, and include a boolean field isSelectable
    add a ListSelectionListener, and in getValueIsAdjusting() (true, not false)
    check the selectionValue's isSelectable. if false, set the selection to the old index.

    you'll also need a few lines of code to handle the initial selection.

  5. #5
    devunion is offline Member
    Join Date
    Jun 2008
    Posts
    56
    Rep Power
    0

    Default

    You can also implement own list cell renderer. I think that it will be helpful for your component.
    Try Controls4J - Advanced Swing Components.

  6. #6
    dbstudio is offline Member
    Join Date
    Sep 2009
    Posts
    5
    Rep Power
    0

    Default replicate the non selectable value through the list

    My problem isn't to get the JList show non selectable values (I use JLabels through a custom listcellrenderer)

    My problem is that when I get more values starting with an A for an example then I get multiple non-selectable "A"s through the list

    like this, the list is filled with an String[] {"Abel","Adam","Solvej","Hugo"};
    then the list show this
    "A"
    Abel
    "A"
    Adam"
    "S"
    Solvej
    "H"
    Hugo

    as you may guess it aint that pretty to have a bunch of "A"s or other "character you wish" through the list so I thought I could brute force search the list but then the creativity stopped as I couldnt figure out the smartest way to remove them so "Abel, Adam" is grouped under the same "A", I guess you would say I should use a JTree but No, hehe, I want it to be done from a JList with custom cell renderers :)

    Hope it will contribute to more solutions :)

    I thank you all for your replies, it made me think abit

    Regards

    David Bundgaard

  7. #7
    Michael Dunn is offline Member
    Join Date
    Jul 2008
    Posts
    62
    Rep Power
    0

    Default

    > I want it to be done from a JList with custom cell renderers

    in the absence of your own errant custom code,
    are you asking for someone to write it for you?

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

  9. #9
    dbstudio is offline Member
    Join Date
    Sep 2009
    Posts
    5
    Rep Power
    0

    Default No, not asking for someone to write the code for me.

    Already got it fixed this morning, now its only some tweaking to do.

    /David

  10. #10
    dbstudio is offline Member
    Join Date
    Sep 2009
    Posts
    5
    Rep Power
    0

    Default I just need to express myself

    But it is no thanks to you guys that I got it fixed.

    /David :)

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,422
    Rep Power
    20

    Default

    Wow, that'll sure encourage people to help when you post your next questions.

    Dimwit.

    db

  12. #12
    dbstudio is offline Member
    Join Date
    Sep 2009
    Posts
    5
    Rep Power
    0

    Default See if you read the messages,

    Quote Originally Posted by Darryl.Burke View Post
    Wow, that'll sure encourage people to help when you post your next questions.

    Dimwit.

    db
    But I thank you too for your honorstly, I think its real nice to see alot of arrogant people telling me that its so easy and telling that I can do it severeal different ways, I hope I will get removed from this forum, but then again it only show who you people truly are and its so nice to see you calling other people names...

    but what I was needing was a kind person like "Fubarable" only that he was missing some pseudo code, I like reading pseudo code, btw do you know what hxxp://en.wikipedia.org/wiki/Pseudo_code is?

    Java Code:
    var askingPeople
    var hoping4answer, enum {nice, arrogant, okay, spot on}
    if askingPeople equal true then
        if hoping4answer equal nice then
             println "Yeay, then I be kind as well"
        else if hoping4answer equal arrogant then
             println "Telling people that they are arrogant bastards"
        else if hoping4answer equal okay then 
             println "Trying to put it into theory and practice"
        else if hoping4answer equal spot on then
             println "Learning from pseudo code given, and reading up on it even more"
        else
             println ""

    Have a nice day DB and I hope you someday will learn to not call people names as I wasnt calling you a dimwit, yet!

    and yes I got the problem solved and I still won't proclaim that it was because of this forums members as I only saw more problems in the answers and I was feeling an arrogant and not helpful manner, as I help and I have helped alot, mostly from the usenet groups I try to provide some form of code and that has been a custom for me and let us call them friends I work and write with.

  13. #13
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    ignoreList++ ;

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

  15. #15
    Michael Dunn is offline Member
    Join Date
    Jul 2008
    Posts
    62
    Rep Power
    0

    Default

    > I hope I will get removed from this forum

    as expected, can't do anything for yourself.
    (now go tell mama "bad man made me cry")

Similar Threads

  1. How to use a JList?
    By glhansen in forum New To Java
    Replies: 3
    Last Post: 03-24-2009, 11:27 AM
  2. JList
    By pinks_70986 in forum New To Java
    Replies: 1
    Last Post: 02-12-2009, 09:36 AM
  3. customizing colors in eclipse
    By uho in forum Eclipse
    Replies: 1
    Last Post: 11-11-2008, 09:46 PM
  4. JOptionPane (customizing)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-14-2008, 12:39 PM
  5. Help with JList
    By Albert in forum NetBeans
    Replies: 1
    Last Post: 07-13-2007, 04:42 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
  •