Results 1 to 2 of 2

Thread: JFrame issues

  1. #1
    ishdevil is offline Member
    Join Date
    Dec 2009
    Posts
    5
    Rep Power
    0

    Default JFrame issues

    Hi guys,

    I am new to Java and I am trying to build a window-based application.

    I have some idea of how to do this, however I have run into a few problems. Here is the frame section of my code, below that I will post my concerns:
    //Method that creates a blank frame
    public static void Form()
    {
    //Code that creates a blank frame
    JFrame frame = new JFrame("Wages");
    frame.setResizable(true);
    frame.setSize(400, 400);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    JPanel panel = new JPanel();
    frame.add(panel);

    JTextArea jat = new JTextArea("Test",10,20);

    JLabel label1 = new JLabel("Label 1");

    JButton button1 = new JButton("Button 1");

    panel.add(label1);
    panel.add(button1);
    panel.add(jat);
    }
    //Main method
    public static void main(String[] args)throws FileNotFoundException
    {
    /*I use a main method because the frame is
    * not the only method that I am using
    */
    Form();
    }

    Core issues:

    1. When I run the program, I have to resize (either maximize or minimize) the window in order for it to show the contents (i.e. the text area, button, and the label).
    2. Whenever I do try to change the location of any of my panel items (eg. jat.setLocation(20, 20);), they still appear in the same location as if I did not set the location to begin with.

    If any of my declarations or method uses seem elementary, remember that I am still a newbie.

    I would appreciate any help that you all can offer.

    Regards,
    Brent

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    call frame.pack() before calling frame.setVisible(true).

    Because you need to learn about LayoutManagers. JPanel uses a FlowLayout by default, and the contentPane of JFrame has, per default, a BorderLayout.

    See this and this and this

Similar Threads

  1. Passing data from one JFrame to another JFrame
    By tarami in forum New To Java
    Replies: 3
    Last Post: 08-06-2009, 05:44 PM
  2. Replies: 4
    Last Post: 04-22-2009, 11:02 PM
  3. Issues with Jva I.O
    By Annatar01 in forum New To Java
    Replies: 0
    Last Post: 02-08-2008, 01:16 AM
  4. Array issues
    By Neo82 in forum New To Java
    Replies: 1
    Last Post: 12-31-2007, 03:22 AM
  5. Compatibility issues with IE7
    By Aneesha in forum New To Java
    Replies: 7
    Last Post: 11-30-2007, 05:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •