How to change the length of a JTextField? (Java/Swing)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Akino877
    New Member
    • Nov 2007
    • 37

    How to change the length of a JTextField? (Java/Swing)

    Hello,

    I am trying to shorten the length of a JTextField with the following code :

    // up to this point, getColumns() returns a value of 35.
    //
    jTextField1.set Columns(20);
    (jTextField1.ge tParent()).inva lidate();
    (jTextField1.ge tParent()).vali date();

    When I ran this code, it did not change the length of the text field at all.

    I wonder if I am writing my code correctly or is there a better/more correct
    way to do this?

    Thank you for your help.

    Akino.
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Hey there!

    Here are a bunch of ideas:

    Oracle Forums is a community platform where you can discuss Oracle products and services, collaborate with peers, and connect with Oracle experts.


    Not sure of the legality of them but, seem to head somewhere.

    Let us know!

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by Akino877
      Hello,

      I am trying to shorten the length of a JTextField with the following code :

      // up to this point, getColumns() returns a value of 35.
      //
      jTextField1.set Columns(20);
      (jTextField1.ge tParent()).inva lidate();
      (jTextField1.ge tParent()).vali date();

      When I ran this code, it did not change the length of the text field at all.

      I wonder if I am writing my code correctly or is there a better/more correct
      way to do this?

      Thank you for your help.

      Akino.
      The columns property of a JTextField is a rough estimation used for the calculation
      of the preferred size of the component. The preferred width is columns times the
      width of the letter 'm' displayed in a certain font. Once a LayoutManager has got
      his hands on the JTextField that column property doesn't mean much anymore.
      It most certainly doesn't determine the maximum number of characters that can
      be entered in the field.

      The columns property is a 'bound property' so it can be changed.

      kind regards,

      Jos

      Comment

      Working...