How to 'properly' extend javax.swing.JFrame with nashorn?
A. Sundararajan
sundararajan.athijegannathan at oracle.com
Tue Mar 3 10:50:19 UTC 2015
Are you looking for a way to introduce a new constructor? That is not
supported. The class extension in nashorn is more like Java anonymous
classes - There too you don't introduce a new constructor - just use
existing constructor to construct new object.
You can workaround with:
function createMyFrame() {
var my = Java.extend(.....) { ... }
my.setSize(800, 600);
my.visible = true;
return my;
}
-Sundar
Christian MICHON wrote:
> Hi,
>
> [ I tried to contact Sundar directly (still no answer), but I'd like to get
> nashorn devs opinion as well. ]
>
> I'm currently trying to extend a javax.swing.JFrame to make a small gui
> using nashorn.
>
> When I'm doing this with java or jruby, it's straight forward and quite
> easy to code a contructor of the derived class to customize dimensions for
> example.
>
> Yet with nashorn I'm struggling: how is named the constructor?
>
> I've a small snippet below to share: I'd like to know what is supposed to
> be in place of XYZ to make frame appear properly (dimensions 800x600).
>
> var myJFrame = Java.extend(javax.swing.JFrame, {
> XYZ: function() {
> setSize(800, 600);
> setVisible(true);
> }
> });
> var my = new myJFrame();
> java.lang.Thread.currentThread().join();
>
>
> Thanks in advance.
> Christian
>
More information about the nashorn-dev
mailing list