Buttons get very small in JToolBar

Hi,

I can’t seem to make the JToolBar bean work.

I have the JToolBar and couple of buttons on a form that runs a method appropriately called “initTool” to initialize the JToolBar. The methods adds the buttons and a separator correctly to the JTooBar, but the buttons get very small and I can’t find a way to get them there natural size.
As expected, the buttons do work since I attached some methods to check it.

Here’s the code for the initTool form method:

elements.bean_224.add(elements['btnRecView']);
elements.bean_224.addSeparator();
elements.bean_224.add(elements['btnAddRec']);

elements.bean_224.upDateUI;

Txs for the help.
mjekl

:oops: I need to specify the imageMedia or text property. This way the JToolBar will rescale the button apropriately.

mjekl

Hi Mjekl,

can you give us a nice (complete) example, of how to use the Jtoolbar?

There ain’t much to it:

Just drop a JToolBar bean on your form and add elements that are allready on your form to it:

elements.bean_224.add(elements['btnRecView']); 
elements.bean_224.addSeparator(); 
elements.bean_224.add(elements['btnAddRec']); 

elements.bean_224.upDateUI;

The code above is a good example of that. the “elements[‘btnRecView’]” is one of these elements on the form, named ‘btnRecView’.

My experience: It works fine for buttons (all things you set on a button still work). When adding fields to a JToolBar bean, they tend to get stretched. You could solve this by setting min and max size on the element, but this is not something Servoy exposes on elements.

Just my 5 cents…

Paul

Hi,

Something I really enjoy with JToolBar is that because we add simple “Servoy Buttons” to it it’s possible to call methods from it!

This “something extra” in JToolBar is what is really missing in Servoys ability to use beans - calling methods from a bean!

When I tried to use JToolBar for the first time I tried to add JButtons to it! I wonder what’s the use of JButton (in Servoy) if we can’t call Servoy methods from it.

I have a stupid ideia about how to call servoy methods from beans, here it goes (I’m going to take flak for opening my big mouth:-)

There could be a mechanism in Servoy that listened to specific elements (beans) to see if they issued some command. This mechanism would be somthing like a Action manager that would bridge registred elements to servoy methods. With registration there could be some optimization of the listening activities of the action manager. So although I do not have a clue about Java in abstract I can’t see why this couldn’t work.

mjekl

Servoy cannot “listen” to commands fired by beans, because there will be nothing fired by a Bean, unless you register a so called “Listener”

As you can see in the functions of a Beans, there are several addXXXXXListeners() functions. They all take a different input param, like an ActionListener, Changelistener etc.

One could write a plugin with functions that returns those Java Listener objects and then you can add those Listener objects to the Bean yourself in scripting.

So, to sum it up: The functions in the plugin would take a global method as parameter and returns a xxxxxListener, which you can add to the bean. Once you have a certain action performed on the bean that will trigger the listener, the global method will be fired.

Just some background. I think that in pretty much all cases, Servoy supports allready the events you need. If they don’t there are good reasons for not supporting them.

Paul

Txs for the explanation Paul.

One could write a plugin with functions that returns those Java Listener objects and then you can add those Listener objects to the Bean yourself in scripting.

And where and how can we get those Listner Objects?
Inline Java! Write them ourselfs?
Or are there any of them available? And how can we get them in Servoy?
I suppose they follow a pretty well defined categorization, is this so?

Just some background. I think that in pretty much all cases, Servoy supports allready the events you need. If they don’t there are good reasons for not supporting them.

Your right. But I suppose beans also introduce the possibility of using some GUI that demand the ability to fire methods like a sliding bar (outlook side menu style).

Mjekl

And where and how can we get those Listner Objects?
Inline Java! Write them ourselfs?
Or are there any of them available? And how can we get them in Servoy?
I suppose they follow a pretty well defined categorization, is this so?

Don’t follow all your questions…

To be able to register Listeners on Beans in methods, you need to have these Listener Objects.

To get them, you need to write a plugin that has functions that returns them. And writing a plugin is done in Java itself (see Servoy website for how to write plugins for Servoy)

Paul

Txs Paul for all the info.

Mjekl