netbeans


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: netbeans

  1. #1
    Join Date
    Jun 2006
    Posts
    7

    netbeans

    Hi,

    I am using netbeans 5.0 IDe,I am not able to insert data dynamically into a jlist as it is creating a private constructor for the jlist when i drag and include it in the frame can anyone help me.

  2. #2
    Join Date
    Aug 2003
    Posts
    313
    Private constructor? That sounds weird to me, do you meann private instance variable? If that's the case, usually you just add a method to your class that is something like:
    Code:
    public void addElementToList(Object obj) {
      myJListModel.insert(obj); // or something like that, i always forget the exact method.
    }
    Then you can add elements from anywhere. You can also make a remove if you need that. The other nice thing is that you can enforce the type that goes into the list since JList is not generified (hopefully it will be soon).

    Hope this helps.
    ~evlich

  3. #3
    Join Date
    Jun 2006
    Posts
    7

    thank you(alternative)

    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;
    }

  4. #4
    Join Date
    Jun 2006
    Posts
    7

    string reverse

    can i get logic and methods to reverse a string

Similar Threads

  1. Netbeans
    By p3aul in forum Java
    Replies: 2
    Last Post: 03-07-2006, 06:47 AM
  2. Replies: 3
    Last Post: 01-07-2006, 12:19 PM
  3. Replies: 3
    Last Post: 11-07-2005, 12:16 AM
  4. Netbeans Webapp deployment exception
    By muzzi in forum Java
    Replies: 0
    Last Post: 05-03-2005, 10:26 AM
  5. NETBEANS IDE VERSION 3.2 RELEASED
    By George Dvorak in forum Open Source
    Replies: 0
    Last Post: 05-06-2001, 09:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center