-1

For some reason, I can't seem to get this to work:

public class App {

    public static void main(String[] args){

            JFrame frame = new JFrame("Hi");
            frame.setSize(300, 400);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);

    }
}

No matter what size I pass to setSize(), the resulting window when I run the program is still tiny. Any suggestions?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
b_pcakes
  • 2,452
  • 3
  • 28
  • 45
  • 1
    is this your complete code? Because this should work just fine (it does for me). Are you sure you're not calling `frame.pack();` somewhere? – Parker_Halo Oct 15 '15 at 07:56
  • 1
    For me it is working what is the issue? – soorapadman Oct 15 '15 at 07:56
  • 1
    For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). The problem would seem to be in code that is **not** shown above. Note that GUIs should be created and changed on the EDT. – Andrew Thompson Oct 15 '15 at 08:07
  • Verify that your program is compiling and you are running the newly compiled code. Code snippet you have pasted seems to work just fine – MikeJ Oct 15 '15 at 12:30

1 Answers1

0

You try this code,will get you a JFrame. and look setPrefered method in the program

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JFrameDemo {

    public static void main(String s[]) {
        JFrame frame = new JFrame("JFrame Source Demo");
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        JLabel jlbempty = new JLabel("");
        jlbempty.setPreferredSize(new Dimension(175, 100));
        frame.getContentPane().add(jlbempty, BorderLayout.CENTER);
        frame.pack();
        frame.setVisible(true);
    }
}
Kumaresan Perumal
  • 1,926
  • 2
  • 29
  • 35
  • `jlbempty.setPreferredSize(new Dimension(175, 100));` Guesses (as to the size). Add an `EmptyBorder` of the required size and stop having to guess. See also [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) (Yes.) – Andrew Thompson Oct 15 '15 at 17:53