0

I'm working on a custom JFrame that has a Box in a JScrollPane initialized as such:

box = new Box(BoxLayout.Y_AXIS);
jScrollPane1.getViewport().setView(box);

Originally, everything works fine, but later when I update the components inside the Box, the components are not clickable (listeners are not invoked, instead the entire Box flickers with each click). Here is the code to update the components:

box.setVisible(!entries.isEmpty());
box.removeAll();
entries.stream()
        .map(entry -> new GUIPassEntry(passman, entry))
        .forEach(box::add);
box.validate();

GUIPassEntry is a custom subclass of JPanel.

I learned that a validate() or revalidate() call is required so that the Box updates visually with the new components. However, after this code is run, the components inside the Box are no longer clickable.

Does anyone know what's going on here?

  • Where do you add the listeners? It looks like there aren't any listeners on the new components you're adding. – David Conrad Jul 11 '18 at 21:41
  • This is a GUI I built via the NetBeans GUI builder, so it is in the netbeans generated code: ` copyBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { onCopy(evt); } }); ` I don't know why the code formatting isn't working here. I put the `` around it. copyBtn is a JButton that is in the GUIPassEntry JPanel. – Travis Bruce Jul 11 '18 at 23:37
  • Oh, and to clarify. The code in my prior comment is executed within the GUIPassEntry constructor call. – Travis Bruce Jul 11 '18 at 23:43
  • *"and to clarify.."* For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). – Andrew Thompson Jul 12 '18 at 00:36
  • Good point, I'm working on doing that but haven't been able to reproduce the issue in a shorter snippet of code yet. However I was able to get it to stop happening if I commented out a line where I was giving a textfield some ghost text (using this person's solution here: https://stackoverflow.com/a/10507193/2953336). – Travis Bruce Jul 12 '18 at 01:44

0 Answers0