title: How to make a single JComponent render aliased text in Swing?
body: <p>Related answer, but not working under OpenJDK 7: <a href="https://stackoverflow.com/a/2266260/1648987">https://stackoverflow.com/a/2266260/1648987</a> (The <code>SwingUtilities2</code> class moved and changed its API.)</p>
  
  <p>I want to display several labels and I want them to be toggleable between being rendered with antialiasing or not. I'm doing it for comparison purposes to see how fonts are rendered with and without antialiasing. For now, I'm trying to achieve that by subclassing <code>JLabel</code>. Here is what I have:</p>
  
  <pre><code>import java.awt.*;
  import javax.swing.JLabel;
  
  public class AALabel extends JLabel {
      /* skipped boring stuff */
  
      public boolean antialiased;
  
      public void paintComponent(Graphics g) {
          Graphics2D g2 = (Graphics2D) g;
          if (antialiased) {
              g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
              g2.setRenderingHint(RenderingHints.KEY_RENDERING,
                RenderingHints.VALUE_RENDER_QUALITY);
          } else {
              g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
              g2.setRenderingHint(RenderingHints.KEY_RENDERING,
                RenderingHints.VALUE_RENDER_SPEED);
          }
          super.paintComponent(g2);
      }
  }
  </code></pre>
  
  <p>But it does nothing. Labels are all antialiased no matter what.</p>
  
  <p>I'm using OpenJDK7 on Linux, but I want it to work on Java 8 too.</p>
  
  <p>I'm also considering switching to a manually painted <code>JPanel</code> (you know, <code>@Override public void paint(Graphics g)</code>, this kind of stuff). If I were to do so, how can I make sure it behaves the same in regards to layout managers – most importantly, it has the same preferred height and resizes properly upon font change?</p>