Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

NetBeans: Adding Elements in a list Box

Zulfi KhanJul 4 2016 — edited Jul 10 2016

Hi,

I am using NetBeans 8.1. I have created a list using swing component. I have a text box (variable name :TF) & 3 buttons. button1 is variable corresponding to the add button. I want to write its handler. I dont know what is the method of list box which can add elements in the list box.

When I press the add button, the data in text field should store in the list box. My variables are:

private javax.swing.JButton button1;

    private javax.swing.JButton button2;

    private javax.swing.JButton button3;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JPanel jPanel1;

    private javax.swing.JScrollBar jScrollBar1;

    private javax.swing.JScrollPane jScrollPane1;

    private javax.swing.JTextField jTF;

    private javax.swing.JList<String> list;

I cant find the addElement ( ) method to add the string from the textbox into the list.

private void button1ActionPerformed(java.awt.event.ActionEvent evt) {                                       

        // TODO add your handling code here:

        String str=jTF.getText();

        list.???

    }    

Some body please guide me about the method to addElement in list box.

Zulfi.

This post has been answered by Zulfi Khan on Jul 10 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 7 2016
Added on Jul 4 2016
4 comments
3,674 views