Results 1 to 3 of 3
  1. #1
    Shahnawaz is offline Member
    Join Date
    Sep 2011
    Posts
    20
    Rep Power
    0

    Default problem with JTextfield..

    hey there, i wrote this code for a form. its just GUI for now, but it won't display JTextfield.. :(


    import javax.swing.*;
    import java.awt.*;
    import java.sql.*;
    public class assignmnt {


    public static void main(String[] args)
    {
    JFrame fr = new JFrame("Aup Student Database");
    fr.setVisible(true);
    fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    fr.setSize(500,500);
    JPanel p = new JPanel(new GridBagLayout());
    fr.getContentPane().add(p, BorderLayout.PAGE_START);

    JLabel lb = new JLabel("Aup Student Database.");
    p.add(lb);
    JPanel p2= new JPanel(new GridBagLayout());
    fr.add(p2);
    fr.getContentPane().add(p2, BorderLayout.WEST);
    GridBagConstraints c= new GridBagConstraints();
    JLabel l1 = new JLabel("<---Search--->");
    c.gridx=0;
    c.gridy=10;
    p2.add(l1,c);
    JLabel l2=new JLabel("Student id: ");
    c.gridx=0;
    c.gridy=11;
    p2.add(l2,c);
    JButton b1=new JButton("Search");
    c.gridx=10;
    c.gridy=12;
    p2.add(b1,c);
    JTextField tf = new JTextField(20);
    c.gridx=10;
    c.gridy=11;
    p2.add(tf,c);
    }
    }

  2. #2
    FlyNn is offline Senior Member
    Join Date
    Feb 2010
    Posts
    128
    Rep Power
    0

    Default Re: problem with JTextfield..

    Your JFrame should be set to visible at the end of the code not at the start. Move the setVisible(true) to the end of the main method.
    Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

  3. #3
    Shahnawaz is offline Member
    Join Date
    Sep 2011
    Posts
    20
    Rep Power
    0

Similar Threads

  1. Replies: 0
    Last Post: 08-30-2011, 09:18 AM
  2. Problem with JTextField.. please help!!
    By Asvin in forum New To Java
    Replies: 21
    Last Post: 12-18-2010, 03:49 PM
  3. Problem with setColumns in JTextField
    By shai in forum New To Java
    Replies: 3
    Last Post: 07-26-2010, 05:41 AM
  4. Problem's with JTextField
    By DC% in forum AWT / Swing
    Replies: 4
    Last Post: 03-10-2009, 05:33 PM
  5. Got problem with JtextField
    By hungleon88 in forum AWT / Swing
    Replies: 4
    Last Post: 12-06-2008, 03:01 PM

Posting Permissions

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