B4J Code Snippet Form Events: form_minimized, form_maximized

I thought it would be handy if one could capture these events in b4j. Many people have posted in the forum about this but I considered it as a self-challenge
to bring it by myself as a local b4j event, thanks to inline Java, JavaObject library and the resourceful b4x community that we enjoy as a special experience.
Here is my code:
enjoy!
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    Dim joform As JavaObject = MainForm
    Dim joStage As JavaObject=joform.GetFieldJO("stage")
    (Me).As(JavaObject).RunMethod("ifStageIsIconified",Array(joStage))
    (Me).As(JavaObject).RunMethod("ifStageIsMaximized",Array(joStage))
   
End Sub

Private Sub form_minimized(isMinimized As Boolean)
    Log($"Form minimized: ${isMinimized}"$)
   
End Sub

Private Sub form_maximized(isMaximized As Boolean)
    Log($"Form maximized: ${isMaximized}"$)
   
End Sub
#if Java

import javafx.collections.ObservableList;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;

public static void ifStageIsIconified(Stage stage){

    stage.iconifiedProperty().addListener(new ChangeListener<Boolean>() {

    @Override
    public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
        Boolean minimized = t1.booleanValue();
        ba.raiseEvent(getObject(), "form_minimized", minimized);
    }
});

}
public static void ifStageIsMaximized(Stage stage){

    stage.maximizedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
            Boolean maximized = t1.booleanValue();
            ba.raiseEvent(getObject(), "form_maximized", maximized);
        }
    });

}
#end if
 
Last edited:

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Trying to get this code to run in a B4J - B4XPages project. I have included the JavaObject lib in my project.
I am getting this error on compile:

error: cannot find symbol
public static void ifStageIsIconified(Stage stage){
^
symbol: class Stage
location: class main



B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    
    Dim joform As JavaObject = MainForm
    Dim joStage As JavaObject=joform.GetFieldJO("stage")
    (Me).As(JavaObject).RunMethod("ifStageIsIconified",Array(joStage))
    (Me).As(JavaObject).RunMethod("ifStageIsMaximized",Array(joStage))
    
    Dim PagesManager As B4XPagesManager
    PagesManager.Initialize(MainForm)
End Sub

And

B4X:
Private Sub form_minimized(isMinimized As Boolean)
    Log($"Form minimized: ${isMinimized}"$)
    
End Sub

Private Sub form_maximized(isMaximized As Boolean)
    Log($"Form minimized: ${isMaximized}"$)
    
End Sub

And

B4X:
#if Java

import javafx.collections.ObservableList;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;

public static void ifStageIsIconified(Stage stage){

    stage.iconifiedProperty().addListener(new ChangeListener<Boolean>() {

    @Override
    public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
        Boolean minimized = t1.booleanValue();
        ba.raiseEvent(getObject(), "form_minimized", minimized);
    }
});

}
public static void ifStageIsMaximized(Stage stage){

    stage.maximizedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
            Boolean maximized = t1.booleanValue();
            ba.raiseEvent(getObject(), "form_maximized", maximized);
        }
    });

}
#end if

What am I missing?
 

jkhazraji

Active Member
Licensed User
Longtime User
Trying to get this code to run in a B4J - B4XPages project. I have included the JavaObject lib in my project.
I am getting this error on compile:

error: cannot find symbol
public static void ifStageIsIconified(Stage stage){
^
symbol: class Stage
location: class main



B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
   
    Dim joform As JavaObject = MainForm
    Dim joStage As JavaObject=joform.GetFieldJO("stage")
    (Me).As(JavaObject).RunMethod("ifStageIsIconified",Array(joStage))
    (Me).As(JavaObject).RunMethod("ifStageIsMaximized",Array(joStage))
   
    Dim PagesManager As B4XPagesManager
    PagesManager.Initialize(MainForm)
End Sub

And

B4X:
Private Sub form_minimized(isMinimized As Boolean)
    Log($"Form minimized: ${isMinimized}"$)
   
End Sub

Private Sub form_maximized(isMaximized As Boolean)
    Log($"Form minimized: ${isMaximized}"$)
   
End Sub

And

B4X:
#if Java

import javafx.collections.ObservableList;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;

public static void ifStageIsIconified(Stage stage){

    stage.iconifiedProperty().addListener(new ChangeListener<Boolean>() {

    @Override
    public vo
In java code add:
[CODE=b4x]#import javafx.stage.Stage;
id changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
Boolean minimized = t1.booleanValue();
ba.raiseEvent(getObject(), "form_minimized", minimized);
}
});

}
public static void ifStageIsMaximized(Stage stage){

stage.maximizedProperty().addListener(new ChangeListener<Boolean>() {

@Override
public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
Boolean maximized = t1.booleanValue();
ba.raiseEvent(getObject(), "form_maximized", maximized);
}
});

}
#end if[/CODE]

What am I missing?
In java code add:
B4X:
#import javafx.stage.Stage;
 
Top