title: Setting the width of TextField
body: <p>I want to set the maximum number of entries a TextField can take, I used:</p>
  
  <pre><code>setMaximumSize
  setPreferredWidth
  SetColumns
  </code></pre>
  
  <p>but was not able to do so. How can I accomplish it?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import java.awt.*;
  import javax.swing.*;
  public class ButtonDemo extends JFrame {
  
      public static void main(String args[]){
          JFrame jfrm = new JFrame("Sample program");
          Container Content =  jfrm.getContentPane(); 
          content.setBackground(Color.red);
          jfrm.setLayout(null);
  
          jfrm.setBounds(250, 150, 400, 400);
          JTextField text = new JTextField();
          Font font1 = new Font("Courier",Font.BOLD,12);
          text.setFont(font1); 
          text.setBounds(50, 15, 100, 30);
  
          JButton button1 = new JButton("PROGRAM"); 
          button1.setFont(font1);
          button1.setBounds(250, 15, 100, 40);
          button1.setBackground (Color.white);
  
          JButton button3 = new JButton("EXIT");
          button3.setBounds(250, 115, 100, 40);
          button3.setBackground (Color.cyan);
          button1.setForeground (Color.red);
  
          JButton button2 = new JButton("USER"); 
          button2.setBounds(250, 65, 100, 40);
          button2.setBackground (Color.WHITE);
  
          jfrm.add(button1);  
          jfrm.add(button2); 
          jfrm.add(button3); 
          jfrm.add(text); 
  
          jfrm.setVisible(true);  
          jfrm.setResizable(false);
      }
  }
  </code></pre>