B4J Question Running static Java method from a class module??

MegatenFreak

Active Member
Licensed User
Hi. I could really use your help.
I've used code I found in these forums (I think it was Erel's) to create a combo box that could update its list as the user types in something in the box (immediate search). The code calls a Java method that must be added to that module:

B4X:
#If Java
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.ComboBox;
import anywheresoftware.b4a.BA;

public static void AddTextChanged(final ComboBox box, final String EventName) {
   box.getEditor().textProperty().addListener(new ChangeListener<String>() {

  @Override
  public void changed(ObservableValue<? extends String> observable,
  String oldValue, String newValue) {
  ba.raiseEventFromUI(box, EventName.toLowerCase() + "_textchanged", newValue);
  }
});
}
#End If

It worked perfectly fine, but now I have a class module in which such a combo box exists. But when I run the App, I get the error message:

error: non-static variable ba cannot be referenced from a static context
ba.raiseEventFromUI(box, EventName.toLowerCase() + "_textchanged", newValue);

I tried removing the static keyword, but that causes another problem: when that class module is opened twice, the content for the combo boxes gets mixed up, naturally.
Any ideas how I can fix this??
Thanks a lot in advance.
 

agraham

Expert
Licensed User
Longtime User
Pass it in an initialize function - like every other view. Forget that, let me think a bit slower and better

I lack details of your class but I assume that it encapsulates a combo box and that the event is raised within the class. In this case each class instance should receive it's own event from its own combo box so it is not immediately apparent to me why they would interfere with each other. Can you elaborate?
 
Last edited:
Upvote 0

MegatenFreak

Active Member
Licensed User
Thanks for your attention;
I'll try to provide a brief overview: (have your headache pills ready!!)
My app consists of a main form containing a TabPane, and every new page opens as a TabPage added to it. This class module that I'm talking about, it actually opens a new tab page, consisting of a small form with a combo box. It's for statistics; the user may want to open several statistical query pages, each for a separate purpose (in one, the combobox contains a customer list, in another a product list, etc.) Instead of adding an individual module for each type of query, I decided to make it a single Class Module, in which I would load the contents of the combo box based on the requested page.
So, this is an example of a problematic situation: the user has opened more than one statistical query page; now, each one calls the Class Module in question; so we've got a few Tab Panes, each containing a combo box with different contents; but when the event for one of them is triggered, it also affects the other ones (practically disables them). It's like: once an event is triggered, it blocks or disrupts the other ones.
I don't understand. I knew if I made it a code module and called it more than once, the combo boxes would interfere, but this is a class module... each page should be completely independent, right? I actually tested normal events for the combo boxes, and surprisingly they interfere as well, so it's not just about the Java code. I don't get it... Do I need to write a separate module for each type of query and have like 30 modules instead of one??

--------------------------------------------------------------------------------
Sorry for the lengthy details, but to facilitate the situation (since I'm not sure my explanations were clear), let me give a simple example of what the purpose of the module is, in case you have a suggestion as to how I should approach the situation:
Imagine that what your app does is show pictures of items; so, in every form in the app you would have a combo box containing a list of items which the user can choose to view images about; since you've got 20 different categories, you don't wanna add 20 modules and layout files, so you make it a single class module... That should work, right?
(Though I'm beginning to wonder if this is because the several pages in my app are not actually separate forms; they are just different "tabs" of a tab pane... They are independent panes, though...)

Again, sorry for writing too much.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
If I've understood (big if!) you are not using classes correctly, it soundes like you are using the class as a code module rather than a class. I would have thought that you need a TabPage class where every instance contains its own form with a combo box. Each new TabPage is a new instance of the class. That way each tab should be independent of all the others and deal only with its own events.
 
Upvote 0

MegatenFreak

Active Member
Licensed User
I guess you're right. I've probably misunderstood the difference between code and class modules, and it's not what I thought it was!
In any case, since this is turning into such a mess, and both my boss's and my own patience are running out (!), I've decided to go with an easy solution and not allow users to open two stat query windows at the same time! Nothing goes wrong when only a single windows is open!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…