java - Why jcombobox is not visible? -


import javax.swing.*; import java.awt.*; import java.awt.event.actionevent; import java.awt.event.actionlistener;   public class dummy{     string newselection = null;      public void init(){         jframe jframe = new jframe("something");         jframe.setvisible(true);         jframe.setsize(new dimension(600, 600));         jframe.setlayout(null);         jframe.setbackground(color.black);          final string[] possiblenoofplayers = {"two","three"};          final jcombobox combobox = new jcombobox(possiblenoofplayers);         newselection = possiblenoofplayers[0];         combobox.setpreferredsize(new dimension(200,130));         combobox.setlocation(new point(200,200));         combobox.seteditable(true);         combobox.setselectedindex(0);         combobox.setvisible(true);         combobox.addactionlistener(new actionlistener() {             @override             public void actionperformed(actionevent actionevent) {                 jcombobox box = (jcombobox) actionevent.getsource();                 newselection = (string) box.getselecteditem();                 system.out.println(newselection);             }         });         jframe.add(combobox);     } } 

i trying add combo box frame. not visible. if click position show options. not visible. please let me know if missing in it.

three things...

  1. you've called setvisible on frame before added it
  2. you're using null layouts
  3. you've not set size comobox, mean (effectively) rendered 0x0 size. (ps- setpreferredsize not doing think should)...

advisable solution...

call setvisible last , use appropriate layout manager


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -