Results 1 to 5 of 5
  1. #1
    sp33dy is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default Direction for creating a custom JTextField input

    Hi,

    I'd like to ask if anyone would kindly point me in the direction of creating my own unique text input field. Basically, I've written a JLabel component with its paint overridden to display the text in a circle layout (pointing the angle of each character to the centre).

    I'd now like to figure out how to write an input field to take the text, rather than popping up a JTextField and using that. Where do I start? I.E. Should I be:

    o Look at extending and overriding the methods in JTextField (my concern is that this natively expects the text to be horizontal. I believe).

    o Research how input from the keyboard can be taken and writing my input field (seems to be a lot of work here to digest and understand).

    I'll continue to research, but wondered if someone can save me sometime by pointing me off in the right direction. I'm comfortable around SWING, but no way an expert; hence asking for help.

    Thanks and kind regards

    Sp33dy

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,192
    Rep Power
    19

    Default

    JTextField with a custom (and fairly complex) UI delegate (i.e. TextFieldUI). Your custom JLabel should also be implemented via a LabelUI class, not by extending JLabel.

    Maybe you can pick up some ideas from my Vertical Label UI Java Tips Weblog

    And it's Swing, not SWING (it isn't an acronym).

    db

  3. #3
    sp33dy is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default

    Thanks db,

    I'll head to your article now. I wasn't aware of the LabelUI class, but I'll get on and learn now. I always knew my JLabel was a hack to prove I could implement what I desired. Thanks for replying so quickly! Also, thanks for the correction on Swing naming. I'd always assumed it was an acronym.

    Kind regards

    Sp33dy

  4. #4
    sp33dy is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default

    Hi db,

    A huge thanks! Using the UI Delegates is a lot easier and cleaner than I'd been doing with extending and overriding the paint methods of the JPanel and JLabel classes!

    Very quick initial test is showing me that I can indeed replace the Look'n'feel whilst tapping into the JTextField's editing capability.

    A huge thanks. Chuffed to nuts!

    Regards

    Sp33dy

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,192
    Rep Power
    19

Similar Threads

  1. input from JTextField
    By Willriker in forum New To Java
    Replies: 13
    Last Post: 08-14-2011, 02:17 AM
  2. Allow only numerical input on JTextField
    By patriotsfan in forum AWT / Swing
    Replies: 3
    Last Post: 05-31-2011, 12:39 PM
  3. Dynamically input text JTextField. Is it possible?
    By africanhacker in forum New To Java
    Replies: 2
    Last Post: 03-21-2011, 04:23 PM
  4. Convert Input from JTextField to int?
    By jls7168 in forum New To Java
    Replies: 7
    Last Post: 02-20-2009, 02:29 AM
  5. Constraining Input in JTextField
    By kataya in forum AWT / Swing
    Replies: 1
    Last Post: 06-26-2008, 06:25 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
  •