• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TextField() Alignment

 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear sir i would like to know that TextField constructor throws a HeadlessException although there is no need to define catch block for that exception why

TextField txt=new TextField();//There is no need to try catch why?
on ther other hand like sleep() method of Thread class most tack try, catch block , why this ambiguilty.
And listen sir one thing more when we use like
txt.setText("1");
it will display text in left starting side of txt field and i want to show it in right side what i have to do.

with regard

Arun kumar maalik
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow. These are two quite different questions, aren't they?

HeadlessException is an unchecked exception, like NullPointerException, ArrayIndexOutOfBoundsException, etc. You are not forced to catch exception types that extend RuntimeException or Error.

Regarding your other question: I'll move this topic to our Swing/AWT forum for that to be answered.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Obviously the exceptions you get from something like Thread.sleep() [InterruptedException] are checked exceptions.
Look at their inheritance in the API. As Ernest has told you, anything which is a subclass of Error or RuntimeException is unchecked, and any other type of Exception is checked, ie you must provide exception handling or the compiler will tell you off.
The reasons you write "throws HeadlessException" after the constructor signature are
  • Because you have used an IDE which found the possibility of a HeadlessException
  • and so any users of your method are warned about the possibility so they can deal with it for themselves.

  • And as for JTextFields: go into the API, where all Java programmers should be every few minutes and look for methods like setHorizontalAlignment. Try them, then tell us whether they work. CR
     
    I am Arthur, King of the Britons. And this is a tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic