how do you edit the size of the popup box to match the size of the textfield?
made it like a autocomplete thing but when the popup coms out its size if based on the words inside. and if it doesnt match any in the DB it just shows a bigger empty box.

im using netbeans 6.5
hirs the codes its not yet complete to the part of wen you click from the text box it automatically puts it in the textfield. im stil trying to figure out how to resize the popup.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane.*;
import java.sql.*;
import java.util.Vector;

public class keytester extends JFrame implements KeyListener
{

public JTextField a1;
public JTextField a2;
public JPanel as;
public boolean option;
public Connection conn;
public Statement stmt;
public String query;
public JList l;
public String letter;
public Popup pop;
public int i;
public JComponent a;
keytester()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/Products?"+"user=root&password=a");

setTitle("Accounts");
setSize(250,200);
setLocation(150,150);
Container container = getContentPane();

as=new JPanel();
container.add(as);
as.setLayout(null);
a1=new JTextField();
a2=new JTextField();
a1.setBounds(30,50,75,20);
a1.addKeyListener(this);
as.add(a1);
}
catch(ClassNotFoundException cnfex)
{
System.err.println("Failed to Load JDBC/ODBC driver.");
cnfex.printStackTrace();
System.exit(1);
}
catch(SQLException sqlex)
{
System.err.println(sqlex);
sqlex.printStackTrace();
}
}
public void keyTyped(KeyEvent e){}
public void keyPressed(KeyEvent e){}
public void keyReleased(KeyEvent e)
{
if(i==1)
{
pop.hide();
}
try {
letter = new String(a1.getText());
zero();
} catch (SQLException ex) {}

}


public void zero()throws SQLException
{
String word=null;
Vector model = new Vector();
option=false;
stmt = conn.createStatement();
query = "SELECT ProdName FROM beverages";
ResultSet rs = stmt.executeQuery(query);

while(rs.next())
{
word=rs.getString(1);
word=word.trim();

if(word.startsWith(letter))
{
model.addElement(word);
option=true;
}

}
l = new JList(model);
l.setOpaque(true);
JScrollPane scrollPane = new JScrollPane(l);
PopupFactory factory= PopupFactory.getSharedInstance();
pop = factory.getPopup(a,scrollPane,189,248);
pop.show();

i=1;

}
public static void main(String[]args)
{
keytester zer = new keytester();
zer.setVisible(true);
}
}