• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kody Wright
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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!

 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • 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
  • 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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic