'What can I do on rewriting JTextFields in Java Swing?

I'm currently developing a calculator app based on Java Swing. I want to make the GUI myself (My own GUI kit), but I'm having some problems on JTextField. I want to rewrite it, making it more pretty. But the result is not what I want, what can I do? (I've tried to override the method paintComponent(Graphics g) but it's not working.)

See the code below:

import javax.swing.*;
import java.awt.*;


/**
 * The custom text field of the app. Will be displayed on top of the Panel.
 * Will be used to display user input.
 *
 * @author abc, 2022/2/22
 * @see javax.swing.JTextField
 */
public class MyTextField extends JTextField {

    public MyTextField(String s) {
        setBorder(null);
        setPreferredSize(new Dimension(700, 50));
        setForeground(Color.WHITE);
        setFont(new Font("Consolas", Font.PLAIN, 18));
        setText(s);
    }

    @Override
    protected void paintComponent(Graphics g) {

        Graphics2D g2d = (Graphics2D) g;

        g2d.setColor(Color.CYAN);
        g2d.drawRoundRect(0, 0, getWidth(), getHeight(), 20, 20);

    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source