java - JComboBox DropDown list is not displayed -


this might duplicate of jcombobox popup menu not appearing , rather old question , not been active quite time, plus answers not solutions, helped problem. decided create new question.

the problem follows: got application of prior colleque, not work @ company anymore. tried adding jcombobox jpanel. jcombobox displayed expected, behaves in same way described seth in question:

1) first click on expand button nothing. second click highlights contents of box, popup still doesn't appear.

2) once i've clicked button , given focus, up/down keystrokes cycle through entries correctly.

i have broken down code think minimum of needed programming, have problem occur. (as 1 comment in mentioned question mentioned provide sscce, never happened).

now here code can provide:

public static class createprojectdialog extends jframe {  private dimension size = toolkit.getdefaulttoolkit().getscreensize();  public createprojectdialog() {      setdefaultcloseoperation(exit_on_close);     int sz_incr = 1;      // passe fontgröße resolution an:     if (size.width > 1920) {         sz_incr = 2;     }      // initialize glass layer     final jpanel panelglass = (jpanel) getglasspane();     panelglass.setlayout(null);     panelglass.setvisible(true);      private static jpanel licborrowpanel = null;      licborrowpanel = new jpanel();     licborrowpanel.setbounds(0, 20, 1000, 500);     licborrowpanel.setvisible(false);     licborrowpanel.setbackground(color.white);     panelglass.add(licborrowpanel); }  public static void main(string[] args) {     hauptframe = new createprojectdialog(); }  public static void licenceborrowdialog() {      int mainwidth = hauptframe.getsize().width;     int mainheight = hauptframe.getsize().height;      // pick date     jcombobox daylist = new jcombobox();     dateformat df = new simpledateformat("dd/mm/yyyy");     calendar caltoday = calendar.getinstance();     date daytoday = caltoday.gettime();     int weekday = caltoday.get(calendar.day_of_week);     string weekdayname = "";     (int = 1; <= 22; i++){         daytoday.setdate(daytoday.getdate()+1);         weekday = daytoday.getday();         weekdayname = translateweekday(weekday);         daylist.additem(i + " day(s) until " + weekdayname + " " + df.format(daytoday));     }     daylist.setopaque(true);     daylist.setselectedindex(2);     daylist.setbounds(mainwidth / 2 - (125*sz_incr), (165*sz_incr), (250*sz_incr), (100*sz_incr));     licborrowpanel.add(daylist);      daylist.addactionlistener(new actionlistener(){         public void actionperformed(actionevent e) {             int numberofdays;             jcombobox dl = (jcombobox)e.getsource();             numberofdays = dl.getselectedindex()+1;             labelselecteddate.settext("<html><body><b>count of days: </b>" + numberofdays + "</html></body>");         }     }); }  //translate weekday int name public static string translateweekday(int day){     string retday;     switch (day) {         case 0:  retday = "monday";             break;         case 1:  retday = "truesday";             break;         case 2:  retday = "wednesday";             break;         case 3:  retday = "thursday";             break;         case 4:  retday = "friday";             break;         case 5:  retday = "saturday";             break;         case 6:  retday = "sunday";             break;         default: retday = "invalid day";             break;     }     return retday; } } 

i tried popoulating more items (as proposed jluzwick) see, if dropdown hidden behind anything, no.

i have never used getrootpane() instead of getcontentpane(), suspected sehtim.

there jcombobox not displayed , accepted answer set setvisible(true) end of constructor. tried , did not change behaviour in case.

the question need answer to, is: how make dropdown list visible, enable user choose entry?

thanks madprogrammer hint regarding code not compiling - found solution , provide here having similar issue.

the problem result of mixing heavy weight , light weight components (awt / swing).

this resulted in light weight popup being used, occluded other components , not visible.

the solution ( if mix of both heavy , light weight has stay ) disable light weight popup forcing application use backup popup. done replaceing following line:

daylist.setselectedindex(2); 

with line:

daylist.setlightweightpopupenabled (false); 

i found solution here: http://de.comp.lang.java.narkive.com/t2gps9vy/jcombobox-poppt-nicht-auf


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -