I'm trying to use the NetBeans GUI editor for creating a UI. I've read that when using JLists you have to define the list model manually. I've tried to do that but it still does not work. The goal is to insert a string in the list when clicking a button.
I suspect that I've maybe put something in the wrong order or messed up something with inheritance.
Please refer to the following video for the problem (watch fullscreen and 720p): http://www.youtube.com/watch?v=HSB-lDGdQPY&feature=youtu.be
Here is most of the affected code (the list is the one called JList1):
private void addBtnActionPerformed(java.awt.event.ActionEvent evt) {
String post = inputField.getText();
defaultModel.addElement(post);
}
.
private void initComponents() {
titleLbl = new javax.swing.JLabel();
addLbl = new javax.swing.JLabel();
inputField = new javax.swing.JTextField();
addBtn = new javax.swing.JButton();
rememberList = new javax.swing.JScrollPane();
DefaultListModel defaultModel = new DefaultListModel();
jList1 = new javax.swing.JList();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
titleLbl.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
titleLbl.setText("Remember to:");
addLbl.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
addLbl.setText("Add new:");
inputField.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
addBtn.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
addBtn.setText("Add");
addBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addBtnActionPerformed(evt);
}
});
jList1.setModel(defaultModel);
rememberList.setViewportView(jList1);