thanks you can observe this code(this works for list selection) and can let me know what can i do in case of generated code with netbeans like this.coz it adds all components variables and methods and declares them as private.
*****import java.sql.*& rest awt;
public class nbcon1 extends javax.swing.JFrame {
Variables Declaration;

public nbcon1() {
initComponents();
// JList(listModel);
}
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jOptionPane1 = new javax.swing.JOptionPane();
jFrame1 = new javax.swing.JFrame();
jPanel2 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jEditorPane1 = new javax.swing.JEditorPane();
jButton2 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jList1 = new javax.swing.JList();
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2.setText("Return");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hreturn(evt);
}
});

jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
hvalcge(evt);
}
});

jScrollPane2.setViewportView(jList1);

org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.add(39, 39, 39)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 615, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jPanel2Layout.createSequentialGroup()
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(74, 74, 74)
.add(jButton2)
.add(257, 257, 257)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 76, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(498, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
.add(20, 20, 20)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 262, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 59, Short.MAX_VALUE)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton2))
.add(57, 57, 57))
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 38, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(40, 40, 40))))
);

org.jdesktop.layout.GroupLayout jFrame1Layout = new org.jdesktop.layout.GroupLayout(jFrame1.getContentPane());
jFrame1.getContentPane().setLayout(jFrame1Layout);
jFrame1Layout.setHorizontalGroup(
jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jFrame1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
jFrame1Layout.setVerticalGroup(
jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jFrame1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(new javax.swing.border.MatteBorder(null));
jButton1.setText("Connect");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hconnect(evt);
}
});

org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(75, Short.MAX_VALUE)
.add(jButton1)
.add(70, 70, 70))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jButton1)
.addContainerGap(23, Short.MAX_VALUE))
);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(69, 69, 69)
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(111, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(105, 105, 105)
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(136, Short.MAX_VALUE))
);
pack();
}// </editor-fold>

private void hvalcge(javax.swing.event.ListSelectionEvent evt) {
// TODO add your handling code here:
if(evt.getValueIsAdjusting()==true){
String sel = jList1.getSelectedValue().toString();
jTextField1.setText(sel);
}
}
private void hreturn(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String pname = jTextField1.getText();
//String popup = "result shown";
jOptionPane2.showMessageDialog(null,pname);
}

private void hconnect(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
database connection;

st =con.createStatement();
String sql = "SELECT proj_name from prjdetails";
rs = st.executeQuery(sql);
n1=rs.getFetchSize();
while(rs.next())
{
String re = rs.getString("proj_name");
n.add(re);
jList1.setListData(n);
}
}catch(SQLException e){
System.out.println("hai"+e);
}catch(ClassNotFoundException e){
System.out.println("unable to load"+ e);
}
jList1.setSelectedIndex(n1);
jFrame1.setVisible(true);
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
//JList(listModel);
new nbcon1().setVisible(true);
}
});
}
/ // Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JEditorPane jEditorPane1;
private javax.swing.JFrame jFrame1;
private javax.swing.JList jList1;
private javax.swing.JOptionPane jOptionPane1;
private javax.swing.JOptionPane jOptionPane2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextField jTextField1;
}