• 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

IllegalArgumentException on jPanel when trying to add objects

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello together,
I am making a Java project for school and I am trying to program a UML-editor. Right now there is an issue in the ActionListener of my program and the NetBeans IDE tells me that it is in line 172 (that is where the panel shall start to add objects). I tried pretty much to find the mistake, but without any success. Do you have an idea where the mistake could be? I hope you can find it in the code I gave here.
Greetings
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Jorit,

welcome to the ranch, and enjoy the stay!

The code snippet gives too little information. I anticipated a little, created this code, and it works flawlessly. Can you show us your code?
By the way: you are mixing the work of a possible LayputManager with hand-made coordinates of your components. In my code (using a simple FlowLayout) you see that the components are placed by the FlowLayout.  But that does not cause an IAE.
 
Jorit Neugebauer
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Piet,
like you asked for the whole code, I copied my complete class. You might be able to notice that I am using the graphical editor of the Java NetBeans IDE. This is why some objects get initialized on their own. I hope you are able to find the issues, I mean it is a pretty long and complex code.
Best greetings
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome again

Unfortunately I couldn't run the whole code; it requires some NetBeans‑specific imports. We would need to know which line the Exception occurs on. Also, have you read the documentation for that add() method? It should say under which circumstances it can throw such an Exception.
 
Piet Souris
Bartender
Posts: 5465
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Jorit,

fortunately I use NeBeans too, it just needs the AbsoluteLayout.jar as library, which is standard available.

The whole clou is that the jPanel1 is using that AbsoluteLayout Manager, and this Manager has its own version of adding components to a panel. Look at where your panel is initially set up, and what syntax NetBeans uses.
Likewise, in the ActionListener of the button, you must use similar syntax:

The code runs smoothly now, albeit that I do not see any changes in the panel.  Can you have a look?
 
Jorit Neugebauer
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Campbell Ritchie,

meanwhile I read the documentation about this exception. Unfortunately I could not find something about my issue, but at least I could try to find it. Also Piet Souris helped me. Either way, thank yo very much for this tip .
 
Jorit Neugebauer
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Piet Souris,

I copied the code you gave and so far it works pretty fine. I can still not see any graphics, but I guess that the Graphics package (java.awt.Graphics) is able to do this. Thank you very much for your help and have a good time.

Best greetings
reply
    Bookmark Topic Watch Topic
  • New Topic