title: Java JPanel painting not working
body: <p>I have a problem making an inner class that extends from JPanel to draw anything on it. I overrided the paintComponent method, and whatever I set to draw from here works fine, but using another method to draw does not work.</p>
  
  <p>Here is my inner class code:</p>
  
  <pre><code>private class Plot extends JPanel {
  
      public Plot() {
          this.setBackground(Color.WHITE);
      }
  
      @Override
      public void paintComponent(Graphics graphic) {
          super.paintComponent(graphic);
          Graphics2D graphic2d = (Graphics2D) graphic;
  
          graphic2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                  RenderingHints.VALUE_ANTIALIAS_ON);
  
          graphic2d.drawOval(0, 0, this.getWidth() - 1, this.getHeight() - 1);
      }
  
      public void drawTitle(final String title) {
          Graphics2D graphic2d = (Graphics2D) this.getGraphics();
          graphic2d.setColor(Color.red);
          graphic2d.drawString(title, 1, 10);
      }
  }
  </code></pre>
  
  <p>Notice the drawTitle method. I just want a custom text to be shown. In my outer class which extends from a JFrame I create an instance of this inner class like this:</p>
  
  <pre><code>private Plot plot;
  
  /** Creates new form GraphicsView */
  public GraphicsView() {
      initComponents();
      plot = new Plot();
      this.add(plot, BorderLayout.CENTER);
  }
  
  public void drawTitle(final String title) {
      this.plot.drawTitle(title);
  }
  </code></pre>
  
  <p>I even create a convenient method to call the inner class drawTitle method (with the same name). I do this because I want this JFrame outer class to be visible on button click, once it is visible (which ensures the init of the graphics) I call the outer class drawTitle which in turn calls the inner class method with the same name and where the string show be drawn... but this does not work, I can't see it on the panel. Here is my button click event:</p>
  
  <pre><code>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      GraphicsView view = new GraphicsView();
      view.setVisible(true);
      view.drawTitle("Hello");
  }
  </code></pre>
  
  <p>Thanks in advance, I will appreciate any help. :)</p>