title: I have some errors with JList rendering JLists
body: <p>So I want to make a main JList that would render JLists inside it.
  The problem is that when I actually add a new string to some JList inside the main JList, I must call mainList.updateUI(); to show the added string in that JList, but it causes this exception:</p>
  <pre><code>Exception in thread &quot;AWT-EventQueue-0&quot; java.lang.NullPointerException: Cannot invoke &quot;javax.swing.plaf.synth.SynthStyle.get(javax.swing.plaf.synth.SynthContext, Object)&quot; because the return value of &quot;javax.swing.plaf.synth.SynthContext.getStyle()&quot; is null
      at java.desktop/javax.swing.plaf.synth.SynthDefaultLookup.getDefault(SynthDefaultLookup.java:43)
      at java.desktop/sun.swing.DefaultLookup.get(DefaultLookup.java:125)
      at java.desktop/sun.swing.DefaultLookup.getBorder(DefaultLookup.java:202)
      at java.desktop/sun.swing.DefaultLookup.getBorder(DefaultLookup.java:210)
      at java.desktop/javax.swing.DefaultListCellRenderer.getNoFocusBorder(DefaultListCellRenderer.java:105)
      at java.desktop/javax.swing.DefaultListCellRenderer.getListCellRendererComponent(DefaultListCellRenderer.java:172)
      at com.martin.gui.CostumJListRenderer.getListCellRendererComponent(CostumJListRenderer.java:10)
      at java.desktop/javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java:1444)
      at java.desktop/javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(BasicListUI.java:1394)
      at java.desktop/javax.swing.plaf.basic.BasicListUI.paintImpl(BasicListUI.java:330)
      at java.desktop/javax.swing.plaf.basic.BasicListUI.paint(BasicListUI.java:306)
      at java.desktop/javax.swing.plaf.synth.SynthListUI.update(SynthListUI.java:90)
      at java.desktop/javax.swing.JComponent.paintComponent(JComponent.java:842)
      at java.desktop/javax.swing.JComponent.paint(JComponent.java:1119)
      at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:952)
      at java.desktop/javax.swing.JComponent.paint(JComponent.java:1128)
      at java.desktop/javax.swing.JComponent.paintToOffscreen(JComponent.java:5311)
      at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBufferedImpl(RepaintManager.java:1657)
      at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1632)
      at java.desktop/javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1570)
      at java.desktop/javax.swing.RepaintManager.paint(RepaintManager.java:1337)
      at java.desktop/javax.swing.JComponent._paintImmediately(JComponent.java:5259)
      at java.desktop/javax.swing.JComponent.paintImmediately(JComponent.java:5069)
      at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:879)
      at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:862)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
      at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:862)
      at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:835)
      at java.desktop/javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:784)
      at java.desktop/javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1898)
      at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:741)
      at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
  </code></pre>
  <p>My goal is to have categories of users with specific rank inside one main list, like how users are listed by ranks in discord.</p>
  <p>This is the code:</p>
  <p>My main list renderer</p>
  <pre><code>public class CostumJListRenderer extends DefaultListCellRenderer {
  
     @Override
      public Component getListCellRendererComponent(JList&lt;?&gt; list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
              Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
              if (value instanceof JList&lt;?&gt;) {
                  c = (Component) value;
              }
              return c;
      }
  
  }
  </code></pre>
  <p>The adding part:</p>
  <pre><code>if(object != null) {
      if(!ScreenGUI.getInstance().coloredString.containsKey(String.valueOf(object.get(&quot;rnk&quot;)))) {
          //checking if the colored string contains rank, if not then new list and rank+color will be assigned
          ScreenGUI.getInstance().coloredString.put(String.valueOf(object.get(&quot;rnk&quot;)), Color.decode(String.valueOf(object.get(&quot;usrClr&quot;))));
          JList&lt;String&gt; list = new JList&lt;&gt;();
          Color color = Color.decode(String.valueOf(object.get(&quot;usrClr&quot;)));
          TitledBorder border = new TitledBorder(new LineBorder(Color.DARK_GRAY, 1), String.valueOf(object.get(&quot;rnk&quot;)));
          border.setTitleJustification(TitledBorder.LEFT);
          border.setTitlePosition(TitledBorder.TOP);
          border.setTitleColor(color);
          border.setTitleFont(new Font(&quot;&quot;, Font.BOLD, 13));
          list.setBorder(border);
          DefaultListModel&lt;String&gt; strModel = new DefaultListModel&lt;&gt;();
          ScreenGUI.getInstance().addOnlineUsers(strModel, String.valueOf(object.get(&quot;prefX&quot;)).charAt(0) + String.valueOf(object.get(&quot;rnk&quot;)) + String.valueOf(object.get(&quot;prefX&quot;)).charAt(1) + &quot; - &quot; + String.valueOf(object.get(&quot;usr&quot;)), String.valueOf(object.get(&quot;rnk&quot;))); //username perimeter
          ScreenGUI.getInstance().list.add(new ListData(list, String.valueOf(object.get(&quot;rnk&quot;)), String.valueOf(object.get(&quot;usrClr&quot;)), strModel));
      }else {
          ScreenGUI.getInstance().list.forEach((current) -&gt; {
              if(current.rank.equals(String.valueOf(object.get(&quot;rnk&quot;)))) {
                  current.model.addElement(String.valueOf(object.get(&quot;prefX&quot;)).charAt(0) + String.valueOf(object.get(&quot;rnk&quot;)) + String.valueOf(object.get(&quot;prefX&quot;)).charAt(1) + &quot; - &quot; + String.valueOf(object.get(&quot;usr&quot;)));
              }
          });
          ScreenGUI.getInstance().updateUsrUI(); //mainList.updateUI();
  }
  </code></pre>
  <p>My ListData class that contains info about JList</p>
  <pre><code>public class ListData {
  
      public JList&lt;String&gt; list;
      public DefaultListModel&lt;String&gt; model;
      public String rank;
      public String color;
  
      public ListData(JList&lt;String&gt; list, String rank, String color, DefaultListModel&lt;String&gt; model) {
          this.list = list;
          this.rank = rank;
          this.color = color;
          this.model = model;
          list.setFont(new Font(&quot;&quot;, Font.BOLD, 14));
          list.setModel(model);
          list.setForeground(Color.decode(color));
          ScreenGUI.getInstance().addToMainUserModel(list);
      }
  }
  </code></pre>
  <p><em><strong>I must also mention that I am using Nimbus theme in JFrame</strong></em></p>
  <p>How can I fix the exception, and am I even doing it correct?</p>
  <p>Thanks for help in the comments!</p>
  <p><strong>FIX:</strong></p>
  <p>You have two options:</p>
  <ol>
  <li>Make JPanel with BoxLayout and then just add JList(-s) to it!</li>
  <li>Batter one, just go to JavaFX and use accordion component!</li>
  </ol>
  <p>(thanks to @GilbertLeBlanc for help)</p>