2

Need to set custom rounded border

JPanel called "user_icon" and "lock_icon" need to make it 4px rounded/radius on top-left and bottom-left only which means the top and bottom on the right is 0

JTextField called "username" and "password" need to make it 4px rounded/radius on top-right and bottom-right only which means the top and bottom on the left is 0

JButton called "login" need to make 4px for right/left/top/bottom

        user_icon = new JPanel();
        user_icon.setBackground(new Color(238, 238, 238));
        user_icon.setBorder(null);
        user_icon.setBounds(212, 120, 40, 44);
        container.add(user_icon);
        user_icon.setLayout(null);
        
        username = new JTextField();
        username.setBorder(null);
        username.setFocusable(false);
        username.setBackground(new Color(245, 245, 245));
        username.setText("Username");
        username.setForeground(Color.GRAY);
        username.setBorder(BorderFactory.createCompoundBorder(username.getBorder(), BorderFactory.createEmptyBorder(0, 10, 0, 0)));
        username.setBounds(252, 120, 220, 44);
        container.add(username);
        username.setColumns(10);
        
        lock_icon = new JPanel();
        lock_icon.setBorder(null);
        lock_icon.setBackground(new Color(238, 238, 238));
        lock_icon.setBounds(212, 175, 40, 44);
        container.add(lock_icon);
        lock_icon.setLayout(null);
        
        password = new JPasswordField();
        password.setFont(new Font("Tahoma", Font.PLAIN, 11));
        password.setBorder(null);
        password.setFocusable(false);
        password.setEchoChar((char) 0);
        password.setBackground(new Color(245, 245, 245));
        password.setText("Password");
        password.setForeground(Color.GRAY);
        password.setBorder(BorderFactory.createCompoundBorder(password.getBorder(), BorderFactory.createEmptyBorder(0, 10, 0, 0)));
        password.setBounds(252, 175, 220, 44);
        container.add(password);
        
        JButton login = new JButton("SIGN IN");
        login.setForeground(Color.WHITE);
        login.setBackground(new Color(229, 33, 35));
        login.setFont(new Font("SansSerif", Font.BOLD, 12));
        login.setBorder(null);
        login.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        login.setFocusPainted(false);
        login.setContentAreaFilled(false);
        login.setOpaque(true);
        login.setBounds(212, 268, 260, 44);
        container.add(login);
nitind
  • 19,089
  • 4
  • 34
  • 43
  • [Java Swing rounded border for Jtextfield](https://stackoverflow.com/questions/8515601/java-swing-rounded-border-for-jtextfield). You'll use a similar technique for `JPanels` and `JButtons`. – Gilbert Le Blanc Aug 20 '23 at 15:00

0 Answers0