I'm having an issue with clearing a JList (which has been added to a JScrollPanel). When I click the "clear" button, it clears fine. But if I first click "print" and then try to click "clear", the contents of the JList do not clear. I believe it's because of the printPanel, because if I use a JTextArea instead of a JPanel when writing out the JOptionPane, the JList clears fine. Any suggestions? Do I need to clear the printPanel somehow?

Here's the basic setup:

Container a = getContentPane();
newArray = new ArrayList();
newList = new JList(newArray.toArray()); // add contents of ArrayList to JList
newScroll = new JScrollPane();
newScroll.getViewport().add(newList); // add JList to scroll pane
clearButton = new JButton("Clear contents");
printButton = new JButton("Print to screen");
clearButton.addActionListener(this);
printButton.addActionListener(this);
a.add(newScroll);
a.add(clearButton);
a.add(printButton);

public void actionPerformed(ActionEvent e) {
if (e.getSource() == clearButton) {
int response = JOptionPane.showConfirmDialog(null, "Clear contents?",
"Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (response == JOptionPane.YES_OPTION){
newArray.clear();
newList.setListData (newArray.toArray());
}
}

if (e.getSource() == printButton) {
JPanel printPanel = new JPanel();
printPanel.add(newList);
JOptionPane.showMessageDialog(null, printPanel);
} // If I use a JTextArea instead of JPanel, the JList clears fine but I can't add the JList or ArrayList with proper formatting?