title: How to make a Round Rectangle JTextField?
body: <p>I want to make a round rectangle JTextField. I write a sub class of AbstractBorder to realize it.But I run into some problems.
  My requirement is:
  <img src="https://i.stack.imgur.com/GYAMP.jpg" alt="enter image description here"></p>
  
  <p>What I get is:</p>
  
  <p><img src="https://i.stack.imgur.com/dftIN.jpg" alt="enter image description here"></p>
  
  <p>My code is :</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.Component;
  import java.awt.Font;
  import java.awt.Graphics;
  import java.awt.Insets;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseListener;
  
  import javax.swing.BorderFactory;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.JTextField;
  import javax.swing.border.AbstractBorder;
  import javax.swing.border.EmptyBorder;
  
  
  public class JTextFieldTest {
      JTextField textField;
      boolean activate = false;
  
      public void createUI(){
          JFrame frame = new JFrame("Test JTextField");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setResizable(true);
  
          MainPanel mainPanel = new MainPanel();
          frame.add(mainPanel,BorderLayout.CENTER);
  
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
      }
  
      public static void main(String[] args) {
          JTextFieldTest jTextFieldTest = new JTextFieldTest();
          jTextFieldTest.createUI();
      }
  
      @SuppressWarnings("serial")
      class MainPanel extends JPanel{
          public MainPanel(){
  
              textField = new JTextField("Please input:");
              Font fieldFont = new Font("Arial", Font.PLAIN, 20);
              textField.setFont(fieldFont);
              textField.setBackground(Color.white);
              textField.setForeground(Color.gray.brighter());
  
              textField.setColumns(30);
              textField.setBorder(BorderFactory.createCompoundBorder(new CustomeBorder(), 
  new EmptyBorder(new Insets(10, 20, 10, 20))));
              textField.addActionListener(new FieldListener());
              textField.addMouseListener(new FieldMouseListener());
  
              add(textField,BorderLayout.CENTER);
              setBackground(Color.blue);
              setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
          }
      }
  
      @SuppressWarnings("serial")
      class CustomeBorder extends AbstractBorder{
          @Override
          public void paintBorder(Component c, Graphics g, int x, int y,
                  int width, int height) {
              // TODO Auto-generated method stub
              super.paintBorder(c, g, x, y, width, height);
              g.setColor(Color.black);
              g.drawRoundRect(x, y, width, height, 20, 20);
          }
  
      }
  
      class FieldListener implements ActionListener{
  
          @Override
          public void actionPerformed(ActionEvent e) {
              // TODO Auto-generated method stub
              System.out.println(textField.getText());
          }
  
      }
  
      class FieldMouseListener implements MouseListener{
          @Override
          public void mouseClicked(MouseEvent e) {
              // TODO Auto-generated method stub
              if(activate == false){
                  textField.setText("");
              }
              activate = true;
              textField.setForeground(Color.black);
  
  
          }
  
          @Override
          public void mousePressed(MouseEvent e) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void mouseReleased(MouseEvent e) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void mouseEntered(MouseEvent e) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void mouseExited(MouseEvent e) {
              // TODO Auto-generated method stub
  
          }
      }
  }
  </code></pre>
  
  <p>I can get another effect by using</p>
  
  <blockquote>
    <p>textField.setOpaque(false);</p>
    
    <p>g.setColor(Color.white);
    g.drawRoundRect(x, y, width - 1, height - 1, 20, 20);</p>
  </blockquote>
  
  <p>Another effect is:
  <img src="https://i.stack.imgur.com/Lp8mU.jpg" alt="enter image description here"></p>
  
  <p>In sum, what can I do to realize my requirement?</p>
  
  <p>@Arijit, it's the effect of your solution when it runs on my computer.
  <img src="https://i.stack.imgur.com/lGaQX.jpg" alt="enter image description here">
  <img src="https://i.stack.imgur.com/h6yS0.jpg" alt="enter image description here"></p>