title: smooth rounded corners in swing
body: <p>I want to make smooth rounded corners for my swing application, but I can't get my desired result...</p>
  
  <p>here's the screenshots:</p>
  
  <p>1.<code>setShape()</code> for JFrame :</p>
  
  <p><img src="https://i.stack.imgur.com/NdqeN.png" alt="enter image description here"></p>
  
  <p>2.overriding <code>paintComponent()</code> method for JPanel instead of using <code>setShape()</code> :</p>
  
  <p><img src="https://i.stack.imgur.com/xVnKl.png" alt="enter image description here"></p>
  
  <p>3.<code>setBackground(new Color(0, 0, 0, 0))</code> for JFrame :</p>
  
  <p><img src="https://i.stack.imgur.com/ZoCre.png" alt="enter image description here"></p>
  
  <p>well, but there's a problem with text quality:</p>
  
  <p>before step 3 :</p>
  
  <p><img src="https://i.stack.imgur.com/bljp8.png" alt="enter image description here"></p>
  
  <p>after step 3 :</p>
  
  <p><img src="https://i.stack.imgur.com/DSIFF.png" alt="enter image description here"></p>
  
  <p>guys I'm confused, I've searched many times but nothing helped me...
  what should I do? please help me</p>
  
  <p>here's the full code :</p>
  
  <pre><code>public class WelcomePage extends JFrame {
  
  private Point initialClick;
  private boolean end = false;
  private JLabel jLabelAppTitle;
  private JPanel jPanelExit;
  private JLabel jLabelHint;
  private int r = 220, g = 0, b = 0;
  private int r2 = 10, g2 = 10, b2 = 10;
  private boolean flag = false;
  
  public WelcomePage() {
      initComponents();
  //    setShape(new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 15, 15));
      centerLocation();
      refreshPage();
  }
  
  public static void main(String args[]) {
      try {
          for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
              if ("Nimbus".equals(info.getName())) {
                  UIManager.setLookAndFeel(info.getClassName());
                  break;
              }
          }
      } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
          e.printStackTrace();
      }
      EventQueue.invokeLater(() -&gt; FadeTransitions.fadeIn(new WelcomePage(), FadeTransitions.NORMAL_FADE, true));
  }
  
  private void refreshPage() {
      Timer timer = new Timer(20, e -&gt; {
          if (!end) {
              if (r == 220 &amp;&amp; b == 0 &amp;&amp; g &lt; 220) {
                  g++;
              } else if (g == 220 &amp;&amp; b == 0 &amp;&amp; r &gt; 0) {
                  r--;
              } else if (g == 220 &amp;&amp; r == 0 &amp;&amp; b &lt; 220) {
                  b++;
              } else if (b == 220 &amp;&amp; r == 0 &amp;&amp; g &gt; 0) {
                  g--;
              } else if (b == 220 &amp;&amp; g == 0 &amp;&amp; r &lt; 220) {
                  r++;
              } else if (r == 220 &amp;&amp; g == 0 &amp;&amp; b &gt; 0) {
                  b--;
              }
              if (!flag) {
                  r2 += 5;
                  g2 += 5;
                  b2 += 5;
                  if (r2 == 250) {
                      flag = true;
                  }
              } else {
                  r2 -= 5;
                  g2 -= 5;
                  b2 -= 5;
                  if (r2 == 10) {
                      flag = false;
                  }
              }
              jLabelAppTitle.setForeground(new Color(r, g, b));
              jLabelHint.setForeground(new Color(r2, g2, b2));
          } else {
              ((Timer) e.getSource()).stop();
          }
      });
      timer.setCoalesce(true);
      timer.setRepeats(true);
      timer.start();
  }
  
  private void centerLocation() throws HeadlessException {
      final Toolkit toolkit = Toolkit.getDefaultToolkit();
      final Dimension screenSize = toolkit.getScreenSize();
      final int x = (screenSize.width - this.getWidth()) / 2;
      final int y = (screenSize.height - this.getHeight()) / 2;
      this.setLocation(x, y);
  }
  
  @SuppressWarnings("unchecked")
  private void initComponents() {
  
      JPanel jPanelMain = new JPanel() {
          @Override
          protected void paintComponent(Graphics g) {
              Graphics2D g2 = (Graphics2D) g.create();
              RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
              qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
              g2.setRenderingHints(qualityHints);
              g2.setPaint(Color.WHITE);
              g2.fillRoundRect(0, 0, getWidth(), getHeight(), 25, 25);
              g2.dispose();
          }
      };
      jPanelExit = new JPanel();
      JLabel jLabelExit = new JLabel();
      JLabel jLabelWelcome = new JLabel();
      jLabelAppTitle = new JLabel();
      jLabelHint = new JLabel();
      JButton jButtonGo = new JButton();
      setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
      setTitle("welcome to My App!");
      setUndecorated(true);
      setBackground(new Color(0, 0, 0, 0));
  
      addWindowListener(new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
              close();
          }
      });
      addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
          public void mouseDragged(MouseEvent evt) {
              thisMouseDragged(evt);
          }
      });
      addMouseListener(new java.awt.event.MouseAdapter() {
          public void mousePressed(MouseEvent evt) {
              thisMousePressed(evt);
          }
      });
  
      jPanelMain.setBackground(Color.WHITE);
      jPanelExit.setBackground(new Color(160, 0, 20));
  
      jLabelExit.setFont(new Font("Tahoma", Font.BOLD, 13));
      jLabelExit.setForeground(new Color(255, 255, 255));
      jLabelExit.setHorizontalAlignment(SwingConstants.CENTER);
      jLabelExit.setText("X");
      jLabelExit.setCursor(new Cursor(Cursor.HAND_CURSOR));
      jLabelExit.addMouseListener(new java.awt.event.MouseAdapter() {
          public void mouseClicked(MouseEvent evt) {
              jLabelExitMouseClicked();
          }
  
          public void mouseEntered(MouseEvent evt) {
              jLabelExitMouseEntered();
          }
  
          public void mouseExited(MouseEvent evt) {
              jLabelExitMouseExited();
          }
      });
  
      GroupLayout jPanelExitLayout = new GroupLayout(jPanelExit);
      jPanelExit.setLayout(jPanelExitLayout);
      jPanelExitLayout.setHorizontalGroup(
              jPanelExitLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                      .addGroup(GroupLayout.Alignment.TRAILING, jPanelExitLayout.createSequentialGroup()
                              .addGap(0, 0, Short.MAX_VALUE)
                              .addComponent(jLabelExit, GroupLayout.PREFERRED_SIZE, 45, GroupLayout.PREFERRED_SIZE))
      );
      jPanelExitLayout.setVerticalGroup(
              jPanelExitLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                      .addGroup(GroupLayout.Alignment.TRAILING, jPanelExitLayout.createSequentialGroup()
                              .addGap(0, 0, Short.MAX_VALUE)
                              .addComponent(jLabelExit, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE))
      );
  
      jLabelWelcome.setFont(new Font("Tahoma", 0, 25));
      jLabelWelcome.setForeground(new Color(0, 0, 100));
      jLabelWelcome.setHorizontalAlignment(SwingConstants.CENTER);
      jLabelWelcome.setText("Welcome");
  
      jLabelAppTitle.setFont(new Font("MV Boli", 0, 29));
      jLabelAppTitle.setHorizontalAlignment(SwingConstants.CENTER);
      jLabelAppTitle.setText("My Swing App");
  
      jButtonGo.setBackground(new Color(100, 20, 80));
      jButtonGo.setFont(new Font("Tahoma", 0, 15));
      jButtonGo.setForeground(new Color(255, 255, 255));
      jButtonGo.setText("GO");
      jButtonGo.addActionListener(evt -&gt; jButtonGoActionPerformed());
  
      jLabelHint.setFont(new Font("Tahoma", 0, 11));
      jLabelHint.setHorizontalAlignment(SwingConstants.CENTER);
      jLabelHint.setText("press GO button");
  
      javax.swing.GroupLayout jPanelMainLayout = new javax.swing.GroupLayout(jPanelMain);
      jPanelMain.setLayout(jPanelMainLayout);
      jPanelMainLayout.setHorizontalGroup(
              jPanelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(jPanelMainLayout.createSequentialGroup()
                              .addContainerGap(48, Short.MAX_VALUE)
                              .addGroup(jPanelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelMainLayout.createSequentialGroup()
                                              .addGap(0, 0, Short.MAX_VALUE)
                                              .addComponent(jPanelExit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                              .addGap(15, 15, 15))
                                      .addGroup(jPanelMainLayout.createSequentialGroup()
                                              .addGroup(jPanelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                      .addComponent(jLabelWelcome, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                      .addComponent(jLabelAppTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                                                      .addComponent(jLabelHint, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                      .addComponent(jButtonGo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                              .addContainerGap(48, Short.MAX_VALUE))))
      );
      jPanelMainLayout.setVerticalGroup(
              jPanelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(jPanelMainLayout.createSequentialGroup()
                              .addComponent(jPanelExit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addGap(64, 64, 64)
                              .addComponent(jLabelWelcome, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addGap(98, 98, 98)
                              .addComponent(jLabelAppTitle)
                              .addGap(86, 86, 86)
                              .addComponent(jLabelHint)
                              .addGap(24, 24, 24)
                              .addComponent(jButtonGo, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addGap(86, 86, 86))
      );
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(layout.createSequentialGroup()
                              .addGap(0, 0, 0)
                              .addComponent(jPanelMain, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
                              .addGap(0, 0, 0))
      );
      layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(layout.createSequentialGroup()
                              .addGap(0, 0, 0)
                              .addComponent(jPanelMain, javax.swing.GroupLayout.DEFAULT_SIZE, 473, Short.MAX_VALUE)
                              .addGap(0, 0, 0))
      );
  
      pack();
  }
  
  private void thisMousePressed(MouseEvent evt) {
      initialClick = evt.getPoint();
  }
  
  private void thisMouseDragged(MouseEvent evt) {
      int thisX = this.getLocation().x;
      int thisY = this.getLocation().y;
      int xMoved = (thisX + evt.getX()) - (thisX + initialClick.x);
      int yMoved = (thisY + evt.getY()) - (thisY + initialClick.y);
      int x = thisX + xMoved;
      int y = thisY + yMoved;
      this.setLocation(x, y);
  }
  
  private void jLabelExitMouseClicked() {
      close();
  }
  
  private void close() {
      end = true;
      FadeTransitions.fadeOut(this, FadeTransitions.FAST_FADE, FadeTransitions.EXIT_ON_CLOSE);
  }
  
  private void jLabelExitMouseEntered() {
      jPanelExit.setBackground(new Color(200, 0, 20));
  }
  
  private void jLabelExitMouseExited() {
      jPanelExit.setBackground(new Color(160, 0, 20));
  }
  
  private void jButtonGoActionPerformed() {
      end = true;
      FadeTransitions.run(this, new ServerManager(this), FadeTransitions.NORMAL_FADE, FadeTransitions.DISPOSE_ON_CLOSE);
  }
  
  }
  </code></pre>
  
  <p>thanks.</p>