B4J Question [Solved, it does work] Add CustomViews in code doesn't work

klaus

Expert
Licensed User
Longtime User
EDIT:
My bad, see post#5.
Attached the correct routine B4J_KCButtonsDemoNew.
KCButtonsDemo is the wrong one.

I am writing a CustomView class.
Adding the CustomView in the Designer works perfectly, but trying to add them in code doesn't work.
I get this error:
B4J version: 4.20 (1)
Parsing code. (0.01s)
Compiling code. (2.33s)
Compiling layouts code. (0.00s)
Compiling generated Java code. Error
B4J line: 27
MainForm.RootPane.AddNode(btnTest3, 190, 200, 60,
javac 1.8.0_92
src\b4j\example\main.java:98: error: incompatible types: kcbutton cannot be converted to Node
_mainform.getRootPane().AddNode((javafx.scene.Node)(_btntest3),190,200,60,40);
when I try to add the CustomView in this line:
MainForm.RootPane.AddNode(btnTest3, 190, 200, 60, 40)

Is there a technical reason why it doesn't work ?
 

Attachments

  • KCButtonsDemo.zip
    7.7 KB · Views: 323
  • B4J_KCButtonsDemoNew.zip
    7.7 KB · Views: 352
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
KCButton is not a Node, so you cannot add it directly.

You can expose pnlBase and add it (or create an AsNode sub that returns pnlBase). However you will also need to initialize it and set its properties.
Not all custom views should be "code supported". Developers can always add them with a pane and a call to LoadLayout.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
This means that the principle in B4J is different than in B4A.
I made a same CustomView class in B4A where I can add the CustomView in the code.
The goal of these CustomViews is to have the same code in both B4A and B4J and probably B4i.
Attached the B4A Class.
 

Attachments

  • B4A_KCButtonClassDemo.zip
    13 KB · Views: 358
Upvote 0

klaus

Expert
Licensed User
Longtime User
Hi Erel,
Sorry for having bothered you !
I did the same approch like in B4A and had the AddToParent routine in the B4J Class, but I didn't use it !?
Don't know why i tryed to add the CustomView like a 'standard' Node. This approch doesn't work in B4A either.
Sometimes I can't see the forest for the trees and need the eyes of someone else.
 
Last edited:
Upvote 0
Top