Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to improve my code for example via JList

 
Radek Gajdos
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm working on adding dynamicly image buttons, for now i achieving this by getting an input from JOptionPane.showInputDialog(), but this approache demands from user knowing the specific names in this case toolTipTexts, but what i want to achieve is to open, after clicking on a jbAddImageButton, a window with JList with ListSelectionModel.MULTIPLE_INTERVAL_SELECTION and to check the choosen positions, and pass them to addImageButton() to add the demanded image buttons. In my search to resolve this topic i read about lists on link, but i fail to implement code on this site in my application. What i'm asking here is to give me some guidence by providing a sample code or sending me to more knowlegde sources or exaples. Maybe somebody was also looking for similar topic and already know the answer. What i post here is working code with JOptionPane.showInputDialog() as a solution to this topic.
 
Radek Gajdos
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i was able to use JList as a component to choose from, but only in SINGLE_SELECTION mode, and what i'm experiencing is that after i choose first animal in second choise after clicking on cancel button it returns me my first animal and i don't know how to fix it. So if somebody knows how to fix it and knows how to use MULTIPLE_INTERVAL_SELECTION in this case, please post. Below my classes.

and second class
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the problem code, I think:



This code assumes that only one entry from the JList will be selected. If you want to use multiple selection, then (without looking it up in the documentation or tutorial) there should be some other method to get all of the selected entries.
 
Radek Gajdos
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, after some changes in code, i'm able to add image buttons from JList in MULTIPLE_INTERVAL_SELECTION mode, and i've eliminated that behaviour of cancel button. It would be nice if you share with me opinions about my code. Below my classes. Greetings.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!