2

I recently updated to AnyLogic PLE 8.4.0 and Java SE 12 on my Windows 10 laptop. And now an AnyLogic model that used to work earlier stops with the error "The method getJComponent() is undefined for the type ShapeTextField." I looked it up in AnyLogic/Help and I notice that getJComponent is identified as "Deprecated" and no alternative is identified. It appears to me that some mismatch happened between AnyLogic and Java updates that resulted in this error. I would appreciate any workarounds to get the model working.

Tried replacing getJComponent() with the following:

  • by getX() - gave error "cannot cast from double to Jtextfield"
  • by getPresentable() - gave error "cannot cast from Presentable to Jtextfield"
  • by getClass() - gave error "Description: Cannot cast from Class to JTextField."
  • by getComponentGraphics() - gave error "Description: The method getComponentGraphics() is undefined for the type ShapeTextField."
  • by equals - gave error "Description: The method equals(Object) in the type Object is not applicable for the arguments ()."

The code is:

((JTextField)(editbox.getJComponent())).setHorizontalAlignment(JTextField.LEFT);

This is defined in Simulation - Simulation Experiment / Java Actions/ Initial Experiment Setup field

Expected result: No error message. And the model should proceed to run window.

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111
  • What AnyLogic version did you upgrade from? If you upgraded from AL7, you will have to change your UI as they switched from Java Swing (what your method is still assuming) to a Web-based UI which is completely different. Replace the editbox in question with a new editbox from the AL8 palette and adjust your code to use the new methods that come with it. – Benjamin Aug 08 '19 at 05:28
  • bullet list needs blank lines around it – Hans Kesting Aug 08 '19 at 07:12
  • `@Benjamin` Thanks for pointing me in the right direction. I did indeed upgrade from AL7. The model was developed by a guest researcher, an expert programmer, who has since gone and I am trying to run it after a gap of several months. I will now search for information on AL8's web-based UI and learn about it. – Sanjay Jain Aug 08 '19 at 12:48
  • this swing method was deprecated in AnyLogic 8.2 and removed in 8.3 I think.. I'm pretty sure that with the current editbox present in AnyLogic you can't align your text. So you will have to create your own edit box from scratch, or you can just erase that code line and continue your life. It's not such an important one. – Felipe Aug 08 '19 at 12:50
  • `@Felipe` Thanks. I commented out the code line and the model compiled. However, as a first step the model prompts user to specify an input file. The provided "Browse" button doesn't work anymore and even if I type the entire path and filename in the text field, the provided "Run" button doesn't work either. Doesn't seem any way around figuring out and rebuilding the UI. I will next look for something online that provides corresponding functions between Java Swing and the new Web-based UI. – Sanjay Jain Aug 08 '19 at 13:07
  • Oh.. if you are using a file chooser there with the PLE, maybe this article I wrote will help out: https://noorjax.com/2018/11/19/using-file-chooser-in-ple/ – Felipe Aug 08 '19 at 18:02
  • `@Felipe` thanks for the link for the article. I see that the article suggests using java.swing library. I understood from the previous comments by `@Benjamin` and you that the Swing methods wouldn't work with AL8.4. Perhaps I misunderstood? – Sanjay Jain Aug 11 '19 at 16:59

1 Answers1

1

Thanks to the inputs from @Benjamin and @Felipe the following worked:

  1. I replaced the editbox and buttons with corresponding artifacts from AL8.4 palette. I copied the code from the earlier artifacts to corresponding fields in the new artifacts. I deleted the artifacts that were from AL7.
  2. I commented out the line that was meant to align the editbox since that capability is not available anymore.

With the above two changes I didn't get the error message about undefined method. The editbox and buttons worked and allowed me to enter XML filename and reading it with an XML parser routine. I have now run into issue with JAXB integration with AL8.4 and haven't been able to get past that yet. I will be posting that as a separate question.