Java Swing Dynamic Field Selection -


i'm not sure how ask question, , i'm there's kind of other solution problem i'm having if can point me in right direction, i'd appreciate it.

in case, issue i'm having have string[] list (called "projects") i'm using populate combo box. want use selection combo box dynamically change form fields listed in gui panel.

my approach, far, isn't dynamic enough because have 100 possible selections combo box when i'm done. far, i've been testing 3 options in box, scaling 100 involve lot of code, , think there must other solution, right? don't know solution is.

string[] projects = {"select project...", "option1", "option2", "option3"};  string[] option1= {"phone", "maxphv"}; string[] option2= {"address1", "address2", "house", "predir", "street", "strtype", "postdir", "apttype", "aptnbr"         , "city", "state", "zip"}; string[] option3= {"phone"};  arraylist<string> fieldslist, fieldslbllist; 

ideally, i'd take name of project selected projects string[] combo box , reference name name of list contains fields want display in panel.

but gather reading on other questions name of variable irrelevant once code compiled.

at point, have set of code clear panel , dynamically select fields, still have manually code replacement each of 100 options. that's not terrible, suppose, think there better way unaware of.

public void resetfields() {     fieldslist.clear();     fieldslbllist.clear(); }  public void setfields() {     if (project.getselectedindex() == 0) {         resetfields();     }     else if (project.getselectedindex() == 1) {         resetfields();         (int = 0; <= option1.length; i++) {             fieldslist.add(option1[i]);             fieldslbllist.add(option1[i]+"lbl");         }     }     else if (project.getselectedindex() == 2) {         resetfields();         (int = 0; <= option2.length; i++) {             fieldslist.add(option2[i]);             fieldslbllist.add(option2[i]+"lbl");         }     } //... onward 100 

the above loop resets display on selection of new option in combo box , loops through options in optionx string[] list , adds values fields array.

is viable way handle dynamic ui coding? and, there way set have specify fields belong each value , not have code section each possible project.getselectedindex() value in setfields()?

use cardlayout, seen here, change form dynamically. given large number of alternatives, hierarchical breakdown among choices might allow use 2 related controls, shown here.

image


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 -