Java tutorial
//package com.java2s; import java.awt.Color; import java.awt.Dimension; import javax.swing.BorderFactory; import javax.swing.JTextField; import javax.swing.border.Border; public class Main { /** * Default textfield design. * * @param requireMinWidth Whether the textfield should have a default min. width set. * @param contents Initial contents. * @return */ public static JTextField defaultTextField(boolean requireMinWidth, String contents) { JTextField jtf = new JTextField(contents); if (requireMinWidth) jtf.setPreferredSize(new Dimension(400, jtf.getPreferredSize().height)); jtf.setBorder(BorderFactory.createCompoundBorder(defaultLineBorder(), BorderFactory.createEmptyBorder(0, 5, 0, 0))); return jtf; } /** * @return Default colored line border */ public static Border defaultLineBorder() { return BorderFactory.createLineBorder(Color.GRAY); } }