java - Set the maximum capacity of JList? -


i trying set maximum capacity of jlist 5 elements. can seem find way of setting minimum using .capacity(). there anyway of setting maximum 5 , dialogue box displayed when exceeds limit? far have this:

string getprocessname = ""; getprocessname = jtextfield1.gettext(); if (info.size() >= 5) {   joptionpane.showmessagedialog(null,"5 elements reached"); }  else {   info.addelement(getprocessname); }   

this displays error message still adds next value on list. suggestions?

jframe frame = new jframe();  //other frame "stuff"  jlist list = new jlist(new object[]{"121", "131", "141", "151" , "111", "181"});     list.setselectionmodel(new myselectionmodel(list, 5)); //<-- magic line right here      frame.setvisible(true); 

this accomplishes task setting size of custom selection model 5.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -