• 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

Exception in thread "main" java.lang.IllegalArgumentException: illegal component position

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello : )

I am in the process of writing a GUI and keep running into an error that I can't seem to get rid of. I still have to add various listeners to make it work, but right now I'm simply trying to make the GUI show up and look the way I want it to.

The error I keep running into is:
Exception in thread "main" java.lang.IllegalArgumentException: illegal component position

I've tried isolating the problem to figure out what exactly is "illegal" about my components...but to no avail. It's entirely possible that I am overlooking some simple error, I've been reading code all day so perhaps my eyes just need a break .

If anyone is able to figure out the problem, I would appreciate it.

Thanks in advance for all the help!

 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are 5 or 6 lines that cause the same complaint, usually the first component placed in each container. If you remove the second argument in the call to add() for each of them, the complaints go away, and your GUI will display. Why the complaint? I'm not sure. I don't have much experience with GridLayout. More research (or a response from someone smarter) should provide a reason.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Exception in thread "main" java.lang.IllegalArgumentException: illegal component position



The add(...) method is used to add components to a Container. Normally the component is added as the last component of the container. The add(...) method also allows you to specify the "position" of the component in the container. That is, first, second, third etc. To add a component at the start (first) you would use:



JLabel.LEFT is not a "position" it is an "alignment" so it is an ivalid value.
 
Kody Wright
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help guys, I managed to get it. After removing the "JLabel.LEFT" and switching a few things around, as per your suggestions, I was able to get it to show correctly.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic