aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Exception in thread "main" java.lang.IllegalArgumentException: illegal component position" Watch "Exception in thread "main" java.lang.IllegalArgumentException: illegal component position" New topic
Author

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

Kody Wright
Ranch Hand

Joined: Mar 06, 2011
Posts: 32
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

Joined: Oct 24, 2010
Posts: 557
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.


Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2174
    
    7
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

Joined: Mar 06, 2011
Posts: 32
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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" java.lang.IllegalArgumentException: illegal component position