I have a scenario where i have splitbutton which i am able to expand using showMenu function.
var comp = Ext.getCmp('Submenu1');
comp.showMenu();
The menu thus opened has another submenu. I tried using the same showMenu function to expand it, but it didn't work. Do we have some function like showMenu for menuitems in extjs?
Properties of MenuItem
Yes, of course, otherwise ExtJS couldn't open the menu as well...
they didn't make the function part of their public API, but this doesn't mean you can't use it. (they may change the behaviour without notice in updates - but if you don't read every line of their release notes carefully, you won't feel the difference...)
In ExtJS, menu items are of xtype menuitem, which has a doExpandMenu function.
I made this fiddle for you.
I have used following snippet to expand the sub menu item.Just before doExpandMenu i had to activate the element.
window.c = Ext.getCmp('TabBar:AdminTab');
c.showMenu();
c = Ext.getCmp('TabBar:AdminTab:Admin_UsersAndSecurity');
c.activate()
c.doExpandMenu();
c.deactivate();
Related
I have been using the following code to add a CheckBox as a side menu item (see below). But after I update my CodenameOne, Eclipse, and Java versions, this code does not work anymore (side menu does not show the checkbox with label "CheckBox", instead it shows a default side menu item with label "Command").
Should I use a different method to add a component to side menu?
public class SideMenuCheck extends Form{
public SideMenuCheck (){
Toolbar myToolbar=new Toolbar();
setToolbar(myToolbar);
Command sideMenuItemCmd = new Command("Command");
CheckBox sideMenuChkBox = new CheckBox("CheckBox");
sideMenuItemCmd.putClientProperty("SideComponent",sideMenuChkBox);
myToolbar.addCommandToSideMenu(sideMenuItemCmd);
show();
}
}
I have also tried adding a button instead of a check box as side menu item, but this code also failed to show the button on the side menu...
Thank you in advance for your help!
That approach for adding a component to the side menu has been deprecated for a while. You should use the API addComponentToSideMenu instead.
The reason this stopped working for you is the switch from the underlying SideMenuBar implementation to the new on-top implementation a while back.
I am trying to create a nested side menu for a CN1 application, similar to the one in the screenshot.
For the nested sidemenu to work, I image it has to stay open when the user presses a command of a dropdown list , so that he/ she can choose an option.
But the CN1 sidemenu appears to close every time and I couldn't find a workaround.
One approach I was trying was to add an action event to the "hamburger menu ", but this doesn't seem to work.
Button sideBtn = (Button)((BorderLayout)bar.getLayout()).getEast();
sideBtn.addActionListener(new ActionListener(){
#Override
public void actionPerformed(ActionEvent evt) {
Toolbar.setPermanentSideMenu(true);
};
Neither does adding Toolbar.setPermanentSideMenu(true) to any other button's action event.
Anther approach I have in mind is to add hidden buttons to the sidemenu and repaint the toolbar when the button is clicked, but this still does not keep the sidemenu open and seems to be not very direct.
Is there anything more straightforward? What would be the best approach?
Thanks in advance for any kind response.
The setPermanentSideMenu method is designed for tablets and not for what you are trying to do. Toggling it after the init(Object) method was invoked doesn't make sense and might break your app.
You didn't list how you added the button to the side menu but adding it using addComponentToSideMenu(Component) should work (notice I didn't use the version that accepts a Command).
I've got standard CreateNewEntity screen. Entity can contain list of entities of some other type. By default there is an add button that opens modal window when user wants to add another entity into collection. However, default modal window was lacking some of the needed functionality so I've done a bit of research. Turns out that default modal screens cannot be modified. So, I found a nice custom modal window helper class. The problem is that I can't seem to be able to access modal window fields in order to enforce needed logic. There are two dropdown lists that are associated. Change in one will result in limiting the other dropdown list options. I'm stuck at this particular part:
var proxy = this.FindControl("DodavanjeParcele");
proxy.ControlAvailable += (s, e) =>
{
var ctrl = e.Control as System.Windows.Controls.Control;
//how to obtain access to ctrl fields?
};
"DodavanjeParcele" is custom modal window. Before this, modal window is instantiated and initialized. It pops up after button click and functions as expected. The only thing missing are above-mentioned rules. I need to set change event handlers for modal window fields in order to define rules. As seen above I tried to cast IProxy as a standard Windows control. This is where I got stuck. I can't seem to find a way to access control fields and set event handlers. Any thoughts?
If I understand you correctly, I'm not sure why you need to search through controls or cast anything.
Control1 is an entity which creates an AutoComplete Box (dropdown list). That selection is copied into a local property in the Control1_Changed method. That property is used as a parameter in a filter query to create Control2.
C#:
private void Control1_Changed()
{
this.MyLocalProperty = this.Control1.SelectedItem;
}
VB.NET:
Private Sub Control1_Changed()
Me.MyLocalProperty = Me.Control1.SelectedItem
End Sub
Just make sure you have Auto Execute Query checked in Control2's Properties and the second control should update and filter when Control1 changes the query parameter.
The code in my screen shots all takes place inside of Yann's Modal Helper so there is nothing special you need to do.
Is there a way to append a menu item to the popup menu that appears by default on right-clicking a GtkNotebook's tab (the one that contains the names of all the open tabs)?
As a somewhat gross hack, it might be possible to use gtk_notebook_get_menu_label() to get the GtkLabel in one of the tab's menu items on that menu, and then use parent-walking from there to find the menu.
Possibly this only works when the menu is being realized/shown, you could try adding event handlers on that label to detect that.
On the other hand, user4815162342's suggestion of re-implementing the menu is way easier.
Looking at the source code, it would appear that there is no way to append to the existing menu: the menu is kept in a private structure, and it is popped up directly on button-press event.
You can disable the default menu, connect to button-press event, and popup your own menu.
I've stumbled on an issue with Comboboxes in javafx2.2. This is the scenario:
Users click on the 'editFile' button.
Another pane becomes visible (with the setVisible method).
This pane contains 6 comboboxes.
Three of them have fixed items: cboReport, cboSales, cboSend. Three of them get their data from a db (ObservableList) and get populated when the pane becomes visible: cboFile, cboCustomer, cboVet
The user selects a file number from the cboFile. The rest of the comboboxes are beeing set with the correct values.
The user presses the save button, the file gets saved as intended.
Next the user presses a close button.
When the window closes, the data on the pane gets resetted through a resetGUI_editFilePane() method. There is have lines like:
...
cboReport.getSelectionModel().clearSelection();
cboSales.getSelectionModel().clearSelection();
cboSend.getSelectionModel().clearSelection();
cboFile.getSelectionModel().clearSelection();
cboCustomer.getSelectionModel().clearSelection();
cboVet.getSelectionModel().clearSelection();
cboFile.getItems().clear();
cboCustomer.getItems().clear();
cboVet.getItems.clear();
...
When the user opens the pane again by pressing the 'editFile' button I notice that only the 'fixed item' comboboxes have cleared their selection, the dynamicly filled comboboxes show the last selected item although the value from the selection itself is null. This looks like a graphics bug to me or am I doing something wrong?
Is there any way around this issue or what is the best method to reset a combobox?
EDIT 2014/08/27:
This is officially not a bug(clearSelection() does not clear value):
https://bugs.openjdk.java.net/browse/JDK-8097244
The official "workaround" is to clear the value of the ComboBox after clearing selection.
cb.getSelectionModel().clearSelection();
// Clear value of ComboBox because clearSelection() does not do it
cb.setValue(null);
It is very simple. You just need to work with the value property of ComboBox. here you go ....
ComboBox c;
c.valueProperty().set(null);
I hope this works for you :-D
I ran into nearly the exact same situation and came across your question while looking for a solution. Fortunately, I came up with a workaround that forces the ComboBoxes to reset. When you reset the data on your pane, instead of doing something like:
cboVet.getSelectionModel().clearSelection();
cboVet.getItems.clear();
do something like this...
parentNode.getChildren().remove(cboVet);
cboVet = new ComboBox(); // do whatever else you need to format your ComboBox
parentNode.add(cboVet);
You'll also need to do a setItems() again on your ComboBox so the new one will be populated. This is not an ideal solution but it seems to be working as I expect the provided clearSelection() method would.
You can retrieve the items and have them all removed:
cboVet.getItems().removeAll(cboVet.getItems());
I've just tested a working solution with the Java JDK 1.7.11:
combobox.setSelectedItem(null);
combobox.setValue(null);
Hope it helps :)
I use reflection with direct manipulation of buttonCell field in ComboBox skin:
#SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> void resetComboBox(ComboBox<T> combo) {
Skin<?> skin = combo.getSkin();
if(skin==null){
return;
}
combo.setValue(null);
Field buttonCellField;
try {
buttonCellField = skin.getClass().getDeclaredField("buttonCell");
buttonCellField.setAccessible(true);
ListCell buttonCell = (ListCell) buttonCellField.get(skin);
if(buttonCell!=null){
StringProperty text = buttonCell.textProperty();
text.set("");
buttonCell.setItem(null);
}
} catch (NoSuchFieldException
| SecurityException
| IllegalArgumentException
| IllegalAccessException e) {
e.printStackTrace();
}
}
I think it's also possible by providing your own buttonCell implementation through buttonCellFactory property
I had the same problem with a ComboBox. The buttonCell of the ComboBox is not updated correctly when I change the items of the ComboBox. This looks like a graphics bug.
I use direct manipulation of buttonCell field in ComboBox.
combo.getButtonCell().setText("");
combo.getButtonCell().setItem(null);
This is the best solution I've found without recreate the ComboBox.
To clear SelectionModel I found nothing better than creating a new instance of Combobox (previous answers update):
myParentNode.getChildren().remove(myCombobox);
myCombobox = new ComboBox();
myParentNode.add(myCombobox);
But this solution evolves other problems: if you use fxml, this combobox will be placed in the wrong place and with wrong parameters. Some fxml parameters are hardly reproduced directly from your controller class code and this is awful to do it every time you need to clear the combobox.
The solution is using custom components instead of creating instances directly in main controller class code, even if these components are standard. This also helps to free some lines in your main controller class by moving component related event methods and other methods to a separate class file, where you use a reference to your main controller class.
How to create custom components in JavaFX FXML Application can be found in http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm , but note that CustomControlExample class is not needed for every custom component in your application, if it already has an entry point class with start(Satge stage) method.
How to resolve possible errors with reference from custom component controller class to main controller class can be found in JavaFx: how to reference main Controller class instance from CustomComponentController class?
I need to clear selection of the combo box. And this code worked for me:
List<Object> list = new ArrayList<>(comboBox.getItems());
comboBox.getItems().removeAll(list);
comboBox.getItems().addAll(list);