# Java - JFrame content not appearing on load.



## PiTCH BLAK (Aug 16, 2004)

I'm writing a Simple Tax Return application in Java in NetBeans 5.0 for school.

This class is just for the GUI, but it is giving me a problem. When it loads the form appears empty:










However, if I click the edge as if to resize the window, everything appears as it should:










I can't for the life of me figure out why it is doing this. How can I get everything to appear on load? What am I missing?


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

public class taxform extends JFrame
{
    JLabel lbAI,lbTW,lbTDE;
    JTextField tfAI,tfTW,tfTDE;
    JButton btnCalc,btnClear,btnHelp;
    
    public taxform()
    {
        lbAI = new JLabel("Annual Income            ");
        lbAI.setFont(new Font("Courier New",Font.BOLD,12));
        lbAI.setLocation(10,10);
        
        lbTW = new JLabel("Tax Withheld             ");
        lbTW.setFont(new Font("Courier New",Font.BOLD,12));
        
        lbTDE = new JLabel("Total Deductible Expenses");
        lbTDE.setFont(new Font("Courier New",Font.BOLD,12));
        
        tfAI = new JTextField(12);
        
        tfTW = new JTextField(12);
        
        tfTDE = new JTextField(12);
        
        btnCalc = new JButton("Calculate");
        
        btnClear = new JButton("Clear");
        
        btnHelp = new JButton("Help");
        
        JPanel pAI = new JPanel();
        pAI.setLayout(new FlowLayout());
        pAI.add(lbAI);
        pAI.add(tfAI);
        
        JPanel pTW = new JPanel();
        pTW.setLayout(new FlowLayout());
        pTW.add(lbTW);
        pTW.add(tfTW);
        
        JPanel pTDE = new JPanel();
        pTDE.setLayout(new FlowLayout());
        pTDE.add(lbTDE);
        pTDE.add(tfTDE);
        
        JPanel pButtons = new JPanel();
        pButtons.setLayout(new FlowLayout());
        pButtons.add(btnCalc);
        pButtons.add(btnClear);
        pButtons.add(btnHelp);
        
        
        setLayout(new GridLayout(4,1));
        add(pAI);
        add(pTW);
        add(pTDE);
        add(pButtons);
        
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int screenWidth = screenSize.width;
        int screenHeight = screenSize.height;
        
        int x = screenWidth / 3;
        int y = screenHeight / 3;
        
        setTitle("Simple Tax Return");
        setVisible(true);
        setBounds(x,y,337,169);
        tfAI.requestFocus();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public static void main(String[] arg)
    {
        new taxform();
    }
}
```
Thanks,
--Ben.


----------



## Chicon (Jul 29, 2004)

Hi PiTCH BLAK,

Your *main* method is incomplete :

*


Code:


    public static void main(String[] arg)
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run() 
           { 
               taxform txf = new taxform();
               txf.setVisible(true);
            }
        });
    }

*I tested it and it works.


----------



## PiTCH BLAK (Aug 16, 2004)

You sir, are my Jesus.

Thank you.


----------



## Chicon (Jul 29, 2004)

PiTCH BLAK said:


> You sir, are my Jesus.
> 
> Thank you.


You're welcome !


----------

