java - JFrame won't show - Not an error in code -
recently every single 1 of apps extends jframe fails show frame. program run , terminate after 8 seconds without ever showing , without error message. happens programs i've made in past new programs.
for testing purposes using basic example oracle documentations.
import java.awt.borderlayout; import javax.swing.jframe; import javax.swing.jlabel; public class test extends jframe{ public static void main(string[] args){ //1. create frame. jframe frame = new jframe("framedemo"); //2. optional: happens when frame closes? frame.setdefaultcloseoperation(jframe.exit_on_close); //3. create components , put them in frame. jlabel emptylabel = new jlabel(); frame.getcontentpane().add(emptylabel, borderlayout.center); //4. size frame. frame.pack(); //5. show it. frame.setvisible(true); } }
i using eclipse , i've tried switching workplaces.
i've looked @ existing threads , found nothing wasn't due coding errors.
how can solve this?
edit: program doesn't output system.out.println() after line:
jframe frame = new jframe("framedemo");
it outputs before that.
alright checked code , works. first things first, jlabel isn't visible if doesn't have in it.
pack(); //basically crushes entire frame if doesn't have objects collapse on.
also, if don't want put in jlabel, don't pack yet. set size with
frame.setsize(width,height);
it shows nothing because collapsed without putting in jlabel. hope answered question want
import java.awt.borderlayout; import javax.swing.jframe; import javax.swing.jlabel; public class test extends jframe{ public static void main(string[] args){ //1. create frame. jframe frame = new jframe("framedemo"); //2. optional: happens when frame closes? frame.setdefaultcloseoperation(jframe.exit_on_close); //3. create components , put them in frame. jlabel emptylabel = new jlabel("blahblahbhalbahlkkdjf"); frame.getcontentpane().add(emptylabel, borderlayout.center); //4. size frame. frame.pack(); //5. show it. frame.setvisible(true); }
}
or set size with
frame.setsize(width,height);
have fun!
Comments
Post a Comment