Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JFrame size is too small

i have created a JFrame in netbeans. But when i run the program, the Jframe size is too small. here is my code.

import javax.swing.JFrame;    

public class Window {

    private static void demo()
    {
        JFrame frame =new JFrame();
        frame.setVisible(true);
    }
    public static void main(String[] args) {
       javax.swing.SwingUtilities.invokeLater(new Runnable(){
      public void run()
      {
          demo();
      }
        });
    }
}

And the output window looks like this.

like image 757
Sam Avatar asked Oct 27 '12 12:10

Sam


2 Answers

You can use frame.setSize(width, height) in order to set its size or frame.setBounds(x, y, width, height) for setting both the location and size.

A better choice would be to call frame.pack() after you add some components to its content pane.

like image 129
Dan D. Avatar answered Oct 27 '22 16:10

Dan D.


Try this way...

Use the setSize(width, height) method of JFrame.

public class Myframe extends JFrame{

  public Myframe(){    
      this.setSize(300,300);    
  }

public static void main(String[] args){

    EventQueue.invokeLater(new Runnable(){

          public void run(){          
            Myframe f = new Myframe("Frame");
            f.setVisible(true);     
          }
      }); 
    }    
}
like image 2
Kumar Vivek Mitra Avatar answered Oct 27 '22 15:10

Kumar Vivek Mitra