How to scroll or move the container in LWUIT-1.5? - java-me

How to scroll the container without using default method called
setScrollable(true),
setScrollableX(true),
setScrollableY(true).
Here my code,
btnLeft = new Button(imgLeft);
btnRight = new Button(imgRight);
Container menuContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
String[] menuArray = {"ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX"};
for (index = 0; index < menuArray.length; index++) {
btnMenu = new Button((String) locale.get(menuArray[index]));
menuContainer.addComponent(btnMenu);
}
menuContainer.setScrollableX(true);
It should move to right & left while clicking right & left button.
Can any one say is it possible in this LWUIT-1.5?

It will be helpful if you can tell us how you want to build your interface.
So, I have tried it with setScrollabeX and it works, but I'm navigating using the focus. If you want to click the Button and make the scroll, you should put in the functionality of the Button something like this:
In the action of the Button Right, you must set the focus to the Button in the right side of the Container and vice versa. Use the Form method setFocused(put the Component here) or using the Button method requestFocus()

Related

Add tree component to OverFlowMenu

I am using codename one to create an application, and i am in front of a situation that is making me use the "tree component" in the pop-up of the OverFlowMenu
how can i do that?
That won't work. The overflow menu uses a renderer approach and isn't very customizable.
Instead add a command to the right side of the toolbar and show a popup dialog pointing at that button e.g.:
popupCommand = toolbar.addMaterialCommandToRightBar("", FontImage.MATERIAL_MORE_VERT, e -> showPopup());
private void showPopup() {
Button b = toolbar.findCommandComponent(popupCommand);
Dialog popup = new Dialog(new BorderLayout());
popup.add(BorderLayout.CENTER, new Tree());
popup.showPopup(b);
}

Removing menu in MFC

In MFC how to remove a menu-item of POPUP type. RemoveMenu() either take ID or position. Since, there is no ID for POPUP menu, option left is by using position.
But I am not getting how and where I can call RemoveMenu().
File Edit Test
Test_submenu_1
Test_submenu_2
Test_submenu_3 > submenu_3_item_1
Test_submenu_4
Test_submenu_5
I want to remove Test_submenu_3? I am not getting how do find CMenu object for Test so that I can call RemoveMenu() by passing position "2" for submenu_3_item_1.
Any suggestion for doing this will be greatly appreciated.
Thanks!
You cannot use LoadMenu, since this function does just that.
After modifying loaded menu it is killed when menu object used to load it goes out of scope. You have to modify menu that is currently used.
Your menu is a popup part of the main menu, second in position. It contains 5 items and second one is another popup. To my understanding, you want to remove this item and popup of this item.
To make it work you will have to ask main window for the current menu:
CMenu* pMenu = GetMenu(); // get the main menu
CMenu* pPopupMenu = pMenu->GetSubMenu(2);//(Test menu with item....)
pPopupMenu->RemoveMenu(2, MF_BYPOSITION);
Of course, this code is from the main frame. If you want to use it elsewhere, you will have to access all using pointer to the main frame.
Try the below. You get the Test sub-menu first (index 2), then once you have that you tell it to remove its Test_submenu_3 submenu by position (also 2).
CMenu topMenu;
topMenu.LoadMenu(IDR_YOUR_MENU);
CMenu& testSubMenu = *topMenu.GetSubMenu(2);
testSubMenu.RemoveMenu(2,MF_BYPOSITION);
'Test' is the 3rd menu item (by position) on the top level menu. It's just been rendered horizontally rather than vertically. Assuming you have a handle to the top level menu use the same code you'd use to the get the sub menus as you would to get the 'Test' menu.
You can use this below code to remove the submenu, by comparing name
bool RemoveSubmenu(CMenu * pMenu) {
for (int pos = 0; pos < pMenu->GetMenuItemCount(); pos++) {
wchar_t *name = new wchar_t[mf.cch + 1];
MENUITEMINFO mf;
ZeroMemory(&mf, sizeof(mf));
mf.cbSize = sizeof(mf);
mf.fMask = MIIM_SUBMENU | MIIM_FTYPE | MIIM_STRING;
mf.fType = MIIM_STRING;
mf.dwTypeData = NULL;
if (!GetMenuItemInfo(pMenu->m_hMenu, pos, TRUE, &mf))
break;
if (mf.hSubMenu != NULL){
mf.fMask = MIIM_TYPE;
mf.fType = MFT_STRING;
++mf.cch;
mf.dwTypeData = (LPSTR)name;
if (!GetMenuItemInfo(pMenu->m_hMenu, pos, TRUE, &mf)){
bRet = false;
break;
}
//
// compare sub menu name (i.e mf.dwTypeData) here, do the required
// modifications
//
pMenu->RemoveMenu(pos, MF_BYPOSITION);
bRet = true;
break;
}
}
}

Sharepoint Toolpart Event Not Firing

I have created a Sharepoint WebPart, and I have given it a custom ToolPart that includes a Grid (a Telerik RadGrid, to be exact, though that is rather irrelevant). I have populated the grid, and created a GridButtonColumn object to add to the grid:
protected override void CreateChildControls()
{
GridButtonColumn c = new GridButtonColumn();
c.ConfirmText = "Really Delete?";
c.ConfirmDialogType = GridConfirmDialogType.RadWindow;
c.ConfirmTitle = "Delete";
c.ButtonType = GridButtonColumnType.LinkButton;
c.Text = "Delete";
c.UniqueName = "DeleteColumn";
grid.Columns.Add(c);
// ...
grid.DeleteCommand += new GridCommandEventHandler(Grid_DeleteCommand);
}
The grid renders correctly - populated with data and with the delete button present.
Now, when I click any of the delete button, the Grid_DeleteCommand() event does not get triggered. However, when I add a random button outside of the grid, it's click event gets triggered:
Button b = new Button();
b.Text = "Hello World";
b.Click += new EventHandler(Button_Click);
I'm not able to debug on this installation of Sharepoint (or maybe I can, but attaching to the process hasn't allowed me to do so yet), so the method of both of those events is simply a redirection to Google. That is how I check to see if the events fire:
string AbsoluteUri ="http://www.google.com";
Page.Response.Redirect(AbsoluteUri);
The only difference I can see between the two is that, with the 'Delete' button, it is nested inside of a Grid control, whereas with the 'Hello World' button, there is no nesting.
How would I be able to have the Grid_DeleteCommand fire when I click the button in the grid?
Using the Telerik Grid control, you should specify button's CommandName in your code.
Adding this line should solve the problem:
c.CommandName = "Delete";

SWT layout selection

I'm trying to make a box that allows you to select some variables, and re-order the ones that are selected. So the LEFT box starts filled, the RIGHT box starts empty. You move items from the left to the right, and on the right you can re-arrange their order (with the up and down buttons). This lets you pick what items you want and in what order (for sorting purposes in another section of the program).
The layout I'm going for looks like of like this:
Unfortunately, it's coming out like... well... :-(
The functionality I'm looking for all works. Yay. I am just having a very hard time with the layout. I think if I can reach the following four primary objectives, I'll be set.
How can I get the OK and CANCEL buttons on the bottom instead of above the multis?
How can I get the multis to have a pre-set size (let's say... 10)
How can I get the arrow buttons to be stacked vertically instead of horizontally?
How can I get the arrow buttons to be between the two multis?
I figure each of these particular objectives are probably one-liners, perhaps a little bit of plumbing here and there...
On a side note, I'm using GridLayout - this might be a poor choice. Is there a better choice for something like this?
Without further ado, here's the code that generates this horrid mess...
#Override
protected Control createDialogArea(Composite parent) {
parent.getShell().setText("Multi-sort");
Composite dialogcomp = new Composite(parent, SWT.NONE);
dialogcomp.setLayout(new GridLayout(3, false));
available = new List(getShell(), SWT.BORDER | SWT.V_SCROLL);
for(String t : MultiSortDialog.availableNames) {
available.add(t);
}
used = new List(getShell(), SWT.BORDER | SWT.V_SCROLL);
for(String t : MultiSortDialog.usedNames) {
used.add(t);
}
createButton(parent, ADD, ">", false);
createButton(parent, REM, "<", false);
createButton(parent, UP, "^", false);
createButton(parent, DOWN, "V", false);
return dialogcomp;
}
I would suggest you simple use the Dialog's default OK and Cancel buttons and not trying to lay out your own. SWT has a nice system for placing them in the system default location (i.e., on Mac OS, the OK button will be on the right, which is the correct location.)
Don't use Dialog.createButton() to create buttons. This creates a button on your dialog which, although it sounds like what you want to do, actually isn't. This creates a button in the style of OK or Cancel buttons, expected to be placed in the button bar composite that the Dialog class owns and styled appropriately for the bottom row OK/Cancel buttons. You want to create a new Button in the composite you're creating. That is:
Button addButton = new Button(dialogcomp, SWT.PUSH);
addButton.setText(">");
addButton.addSelectionListener(...);
To stack the buttons vertically, create a new composite inside dialogcomp to contain them.
To put the arrow buttons between the Lists, you need to ensure that you add things in the correct order. With a GridLayout, you need to add widgets in the order that you want them to appear.
Other points:
Don't change the title of the dialog by calling Shell.setText(). Call setText() in your
Don't try to parent your Lists inside the parent shell. You're given a composite to put things in. This will wreak havoc on your layouts. You're basically hoisting widgets up into things you don't own and don't layout. Instead, put it in the Composite you created.
You may also wish to create buttons with the type SWT.ARROW | SWT.LEFT instead of simply drawing a < sign. It may be more visually appealing. Just something to investigate.
A simple rearrangement of your code, creating Buttons properly, and creating a new composite to hold the buttons, will get you much closer:
Composite dialogcomp = new Composite(parent, SWT.NONE);
dialogcomp.setLayout(new GridLayout(3, false));
available = new List(dialogcomp, SWT.BORDER | SWT.V_SCROLL);
for(String t : MultiSortDialog.availableNames) {
available.add(t);
}
Composite buttonComposite = new Composite(dialogcomp, SWT.NONE);
buttonComposite.setLayout(new GridLayout(1, false));
Button addButton = new Button(buttonComposite, SWT.PUSH);
addButton.setText(">");
Button removeButton = new Button(buttonComposite, SWT.PUSH);
removeButton.setText("<");
Button upButton = new Button(buttonComposite, SWT.PUSH);
upButton.setText("^");
Button downButton = new Button(buttonComposite, SWT.PUSH);
downButton.setText("v");
used = new List(dialogcomp, SWT.BORDER | SWT.V_SCROLL);
for(String t : MultiSortDialog.usedNames) {
used.add(t);
}
This will probably get you pretty close to what you want. However, you will probably want to apply GridDatas for each of your instances. For example, your two Lists will probably want to grab and fill horizontally and vertically to fill the layout as the Dialog is resized. But I'll leave that as an exercise for the reader.

C# TableLayoutPanel replace control?

I was wondering if it was possible to replace one control in a TableLayoutPanel with another at runtime. I have a combo box and a button which are dynamically added to the TableLayoutPanel at runtime, and when the user selects an item in the combo box and hits the button, I'd like to replace the combobox with a label containing the text of the selected combo box item.
Basically, if I could simply remove the control and insert another at it's index, that would work for me. However I don't see an option like "splice" or "insert" on the Controls collection of the TableLayoutPanel, and I was wondering if there was a simple way to insert a control at a specific index. Thanks in advance.
Fixed this by populating a panel with the two controls I wanted to swap and putting that into the TableLayoutPanel. Then I set their visibility according to which I wanted to see at what time.
This is what I've been able to come up with for what I needed. It gets the position of the ComboBox and makes a new label using the selected value.
// Replaces a drop down menu with a label of the same value
private void lockDropMenu(ComboBox dropControl)
{
TableLayoutPanelCellPosition pos = myTable.GetCellPosition(dropControl);
Label lblValue = new Label();
myTable.Controls.Remove(dropControl);
if (dropControl.SelectedItem != null)
{
lblValue.Text = dropControl.SelectedItem.ToString();
lblValue.Font = lblValue.Font = dropControl.Font;
// Just my preferred formatting
lblValue.AutoSize = true;
lblValue.Dock = System.Windows.Forms.DockStyle.Fill;
lblValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
myTable.Controls.Add(lblValue, pos.Column, pos.Row);
}
}

Resources