Disable item from JList
How can we disable an item from JList?
How can we disable an item from JList?
you need to get the DefaultListModel from your JList and remove the item at index.
DefaultListModel dlm = (DefaulListMOdel) jList.getModel();
dlm.remove(index);
bye
Message was edited by:
RPalluk
it is not working..
Exception in thread "main" java.lang.ClassCastException: javax.swing.JList$1 can
not be cast to javax.swing.DefaultListModel
at visualjava.project.MainFile.initTools(MainFile.java:110)
at visualjava.project.MainFile.<init>(MainFile.java:36)
at visualjava.project.MainFile.main(MainFile.java:131)
Press any key to continue . . .
Why did you repost?
You got the same answer you got in your other posting which is simply to remove the item form the JList.
If you don't know how to do this then read the JLIst API and follow the link on "How to Use LIsts" for a working example.
i have used this in a jTable and work but the jlist seems different.
You can initalize the jList with a DefaultListModel and use it to modify the data, from the error seems that isn't possible to cast a ListModel to DefaultListModel but i don't know
why, ListModel is an interface of DefaultListModel.
see this example.
http://jug.org.ua/wiki/display/JavaAlmanac/Listening+for+Changes+to+the+Items+in+a+JList+Component
sorry for my bad english!
Roberto