Skip to main content

extending widgets

4 replies [Last post]
kasper110382
Offline
Joined: 2008-02-13
Points: 0

Hello everybody

I've started using JavaFX a couple of days ago and I'm pretty glad I did! What used to take me days in "plain old Swing" now gets done in probably half the time... Anyways I have a problem though... I've started extending the widget classes to get some more specialized types that will save me a lot of coding. It worked with Label:

public class HeaderLabel extends Label {
}
trigger on (new HeaderLabel) {
font = Font {
size: 18
};
}

But when I try to do the same thing with an internal frame ...

public class ProfileInternalFrame extends InternalFrame {
}
trigger on (new ProfileInternalFrame) {
title = "Profile";
width = 400;
height = 300;
}

... I get this error:

Can't instantiate abstract type *

Can anybody tell me what's wrong?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12
Points: 0

I can execute code
[code]
public class ProfileInternalFrame extends InternalFrame {
}
trigger on (new ProfileInternalFrame) {
title = "Profile";
width = 400;
height = 300;
} [/code]
without any errors.
I use a JavaFX interpreter from https://openjfx.dev.java.net/servlets/ProjectDocumentList
Which version of JavaFX Script do you use?

kasper110382
Offline
Joined: 2008-02-13
Points: 0

I'm using the same (newest) interpreter as you.

I can also execute the code per se, but when I try to instanciate a new ProfileInternalFrame from another script it doesn't seem to work. I am certain that I can reference classes between the two files though, since my HeaderLabel (examplified above) is also located in the same file as ProfileInternalFrame... Is it maybe something specific to internal frames?

alexsch
Offline
Joined: 2007-07-12
Points: 0

I think each class should be declared in the fx file with the same name to be accessible
from others files.

The following example works for me:
------------HeaderLabel.fx -----------------------
[code]
package pack;

import javafx.ui.*;

public class HeaderLabel extends Label {
}
trigger on(new HeaderLabel) {
font = Font {
size: 18
};
}
[/code]
------------ProfileInternalFrame.fx -----------------------
[code]
package pack;

import javafx.ui.*;

public class ProfileInternalFrame extends InternalFrame {
}

trigger on(new ProfileInternalFrame) {
title = "Profile";
width = 400;
height = 300;
}
[/code]
------------Main.fx -----------------------
[code]
package pack;

import javafx.ui.*;

Frame{
width: 500
height: 600

content: DesktopPane{
frames: ProfileInternalFrame{
content: HeaderLabel{ text: "Hello World!"}
}
}

visible: true
}

[/code]

kasper110382
Offline
Joined: 2008-02-13
Points: 0

Aha, that wasn't really what the problem was, but your code gave me the crucial hint :-) I forgot to use the package statement at the beginning of the scripts ... Being a JFX newbie I didn't notice them in the tutorials I've read ;-)

Thank you very much!

PS: It is possible to have more than one class in a script with a totally different name, I have a script called "SharedClasses.fx" and it contains both ProfileInternalFrame and HeaderLabel ... and now it works, thanks you!