Results 1 to 2 of 2
  1. #1
    stayfierce is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default Change the Font Size and Text Position

    I am trying to change the font size of a text field. I would like the font that is typed in the text field to be bigger and bolded.

    I have tried this, but it does does not work:

    Java Code:
    Font font1 = new Font("SansSerif", Font.BOLD, 20);
    JTextField textfield = new JTextField ();
    textfield.setFont(font1);


    Also, I want the texted to be centered in the textfield. I have used this:

    Java Code:
    textfield.setHorizontalTextPostion.CENTER
    textfield.setVerticalTextPostion.CENTER

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Just creating a font does nothing. You have to set the JTextField's font via setFont. Note that this will only work on the textfield that is specifically set this way. If you want to change ALL textfields, you'll need to look into look and feel.

Similar Threads

  1. change text size in all GUI components
    By itaipee in forum AWT / Swing
    Replies: 2
    Last Post: 08-07-2009, 05:59 AM
  2. Replies: 5
    Last Post: 04-25-2009, 09:00 PM
  3. Replies: 4
    Last Post: 02-22-2009, 07:31 AM
  4. Replies: 0
    Last Post: 06-25-2008, 11:33 AM
  5. how to set font size for a xml value
    By bala_kj in forum Advanced Java
    Replies: 3
    Last Post: 04-01-2008, 12:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •