The code is like this: JTextField txt = new JTextField(); txt.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.red));