Friday, 15 February 2013

java - JFrame won't show - Not an error in code -


My every app that spans the GeFram lately, really fails to show the frame. The program will run and then will never show anything after about 8 seconds and without any error message it will expire. This is for all the programs done by me in the past as well as for any new programs.

For testing purposes, I am using the basic example from Oracle documentation.

  Import java.awt.BorderLayout; Import javax.swing.JFrame; Import javax.swing.JLabel; Jeffrey in public class test {public static zero main (string [] Args) {// 1. Create Frame Jeffrey Frame = New GeFram ("Frame Demo"); // 2. Optional: What happens when the frame stops? Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); // 3 Create components and keep them in frames JLABABLE blank label = new JLab (); Frame.getContentPane () Add (empty label, BorderLayout.CENTER); // 4 Frame size frame.pack (); // 5 Show it Frame.setVisible (true); }}  

I am using Eclipse and I have already tried to change workspaces.

I have seen the current thread and found nothing that was not due to coding errors.

How can I solve it?

Edit: The program outputs nothing to System.out.println () after this line:

  Jeffreem frames = new jefram ("frame demo" );  

This does anything before it.

OK, so I checked your code and it works first things first, your JLable appeared There is nothing in it if there is nothing in it.

  pack (); // basically crushes the whole frame if it does not have to collapse objects  

In addition, if you do not want to put anything in your JLable, it is still packed Do not just set it in a fixed size with

  frame.setSize (width, height);  

It just does not show anything because you collapsed without putting anything in JLable I hope that I have answered your question basically, this is what you want Are

  import java.awt.borderLayout; Import javax.swing.JFrame; Import javax.swing.JLabel; Jeffrey in public class test {public static zero main (string [] Args) {// 1. Create Frame Jeffrey Frame = New GeFram ("Frame Demo"); // 2. Optional: What happens when the frame stops? Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); // 3 Create components and keep them in frames JLABABLE blank label (new) JLab ("KDJF for BalBlack"); Frame.getContentPane () Add (empty label, BorderLayout.CENTER); // 4 Frame size frame.pack (); // 5 Show it Frame.setVisible (true); }  

}

Or you can simply set the size with

  frame.setSize (width, height);  

Have fun!


No comments:

Post a Comment