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);
}
}
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.
Re: problem with JTextfield..