java - JAR file messes GUI? -


i've got homework make simple login window. after finished coding tried exporting file runnable jar file, , after running jar file saw had messed gui. jpasswordfield fills entire jframe reason. have no clue might problem because runs fine ide. help?

what want like

what looks when run jar

here code (works fine in eclipse ide):`

public class login extends jframe {  private static final long serialversionuid = 1l; private static jtextfield user = new jtextfield(); private static jpasswordfield pass = new jpasswordfield(); private static jbutton loginbtn = new jbutton("login"); protected string[] args; private static jframe frame = new jframe("log in");   public login(){      loginbtn.addactionlistener(new actionlistener(){         @suppresswarnings("deprecation")         public void actionperformed(actionevent e){             if(user.gettext().equals("admin") && pass.gettext().equals("nimda")){                  //system.out.println("hello admin!");                 joptionpane.showmessagedialog(null, "logged in!");                 mylog.main(args);                 frame.setvisible(false);             }             else{                  //system.out.println("login error!");                 joptionpane.showmessagedialog(null, "login error!");             }         }     });  }  public static void main(string[] args) {      @suppresswarnings("unused")     login login = new login();     jlabel username = new jlabel("username");     jlabel password = new jlabel("password");      frame.setsize(260, 200);     frame.setresizable(false);     frame.setdefaultcloseoperation(jframe.exit_on_close);     frame.setvisible(true);      username.setbounds(20, 60, 100, 20);     password.setbounds(20, 85, 100, 20);     pass.setbounds(85, 85, 150, 20);     user.setbounds(85, 60, 150, 20);     loginbtn.setbounds(88, 110, 50, 20);      frame.add(username);     frame.add(password);     frame.add(loginbtn);     frame.add(user);     frame.add(pass);  }           } 

thanks in advance guys! cheers!

calling setvisible on jframe before adding components causes problem likely. should add components want jframe before calling setvisible, setvisible validates components (lays them out).

what setvisible api, you'll see talks validating components

what validate api


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -