I would like to self-draw the checkmark of a Checkbox, as explained here.
This requires setting the CheckBox to checkBox.Appearance = Appearance.Button and then disabling the borders. Meaning, the CheckBox is now rendered as if it was a button. When it is checked, it is rendered as a depressed button.
Unfortunately, a depressed button has its text shifted slightly to the right and downwards. This behaviour is not commonly seen in a CheckBox.
var cb = new Checkbox();
cb.Paint += delegate (object sender, PaintEventArgs e)
{
// Here you can custom-draw the Checkmark.
// (but I'd like to fix the text-shifting first)
};
cb.Appearance = Appearance.Button;
cb.TextAlign = ContentAlignment.MiddleRight;
cb.FlatStyle = FlatStyle.Flat;
cb.FlatAppearance.BorderSize = 0;
Is it possible to configure a Button (or a CheckBox configured as Button) so that the text is not shifted when it is being depressed?
Related
While swiping a form, the growing left part of the screen is just white until the swiping is done, when the "back-to" form finally is painted. Is this by design? I expected the "back-to" form either to be gradually revealed, or to slide in from the left.
On iOS and Android, the form being swiped also seems to turn white, so the whole screen is white until the swiping is over. This is not the case with the simulator, however, where you can see the form until it's swiped all the way out.
Code to reproduce the behaviour:
Form redForm = new Form("Red Form");
redForm.getAllStyles().setBgColor(0xff0000);
Button btnToBlueForm = new Button("Go to blue form");
redForm.add(btnToBlueForm);
Form blueForm = new Form("Blue Form");
blueForm.getAllStyles().setBgColor(0x0000ff);
LazyValue<Form> lazyRedForm = (Object... args) -> redForm;
SwipeBackSupport.bindBack(blueForm, lazyRedForm);
btnToBlueForm.addActionListener((ActionListener<ActionEvent>) (ActionEvent evt) -> {
blueForm.show();
SwipeBackSupport.bindBack(blueForm, lazyRedForm);
});
redForm.show();
Press the button in the red form. The blue form now appears. Swipe back and observe the effects.
That's because of the SlideFade mode in the transition. If you switch it to Slide it should work as expected with the background. Here's a version of your code that works as you would expect by applying the style to the content pane:
Form redForm = new Form("Red Form");
redForm.getContentPane().getAllStyles().setBgColor(0xff0000);
redForm.getContentPane().getAllStyles().setBgTransparency(255);
Button btnToBlueForm = new Button("Go to blue form");
redForm.add(btnToBlueForm);
Form blueForm = new Form("Blue Form");
blueForm.getContentPane().getAllStyles().setBgColor(0x0000ff);
blueForm.getContentPane().getAllStyles().setBgTransparency(255);
LazyValue<Form> lazyRedForm = (Object... args) -> redForm;
SwipeBackSupport.bindBack(blueForm, lazyRedForm);
btnToBlueForm.addActionListener((ActionListener<ActionEvent>) (ActionEvent evt) -> {
blueForm.show();
SwipeBackSupport.bindBack(blueForm, lazyRedForm);
});
redForm.show();
The reason this works as opposed to the original code is that SlideFade is two separate transitions one moving/fading the title and the other sliding the content pane alone. Since the content pane is transparent the background isn't painted as we assume it's the form background. By setting the content pane color/opacity we get the exact same effect at a layer the SlideFade will "see".
This creates a SwipeableContainer inside a Tab, but the swipe gesture is always detected by both the SwipeableContainer and the Tab (i.e. It shows the button under SwipeableContainer and move the page back to the left tab simultaneously when my finger swipes from left to right), which makes it very difficult to press the button behind it.
Is there any way to detect the gesture on SwipeableContainer only?
Tabs main_tab = new Tabs();
Container query_container;
Container history_container;
history_container = new Container(new BoxLayout(BoxLayout.Y_AXIS));
MultiButton his_btn = new MultiButton("History");
Button delete_btn = new Button("delete");
SwipeableContainer his_list_container = new SwipeableContainer(delete_btn,his_btn);
history_container.add(his_list_container);
main_tab.addTab("query", query_icon, query_container);
main_tab.addTab("history", history_icon, history_container);
I think that you can just remove the Swipe Gesture for the Tabs using the following method:
main_tab_.setSwipeActivated(false);
From the codenameone documentation:
public void setSwipeActivated(boolean swipeActivated)
Setter method for swipe mode
I want to append a child control (button) programmatically inside a border left corner at run time based on event of a check box. my code on check box true value:
var btn = new System.Windows.Controls.Primitives.ToggleButton();
btn.Style = App.Current.Resources["ToggleButtonStyle"] as Style;
ctrlBorder.Child = btn;
ctrlBorder.Tag = btn;
Now the issue is if i am adding as child, all other controls inside the control as invisible and only btn is displayed. How can I append a btn inside a border control.
Also, on unchecking the checkbox the btn should disappear.
Any help is greatly appreciated!
By assigning ctrlBorder.Child you overwrite its only child (one allowed for border control). Try to append your control to the actual child of the border (Grid? StackPanel?)
see https://stackoverflow.com/a/1871229/1346098 :
Grid tmpGrid = ctrlBorder.Child as Grid;
tmpGrid.SetRow(btn, 3);
tmpGrid.SetColumn(btn, 4);
tmpGrid.Children.Add(btn);
I'm making a list of containers programmatically. These containers have a table layout with two cells. In first cell I'm showing a checkbox and in second cell is a multibutton:
In some rows I would like disable user to click on a checkbox. I've tried using .setHidden(true), setVisible(true), etc.. on a checkbox but in that case checkbox is not visible(which is also acceptable) but in that case it is not preserving it's space and data in rows are not vertically aligned(as you see in the image). Does anyone know how to achieve this??? Graying and disabling the checkbox would be great, but not showing it and preserving it's space would be acceptable.
Here's the code:
Container list = findContainerOrders(f);
list.setScrollableY(true);
LinkedHashMap htJSONObject;
//al is a ArrayList
for(int i=0; i < al.size(); i++){
htJSONObject = (LinkedHashMap)al.get(i);
Container cr = new Container();
TableLayout gr = new TableLayout(1, 2);
gr.setGrowHorizontally(true);
cr.setLayout(gr);
final MultiButton b = new MultiButton();
b.setName((String)htJSONObject.get("text1"));
b.setTextLine1((String)htJSONObject.get("text2"));
b.setTextLine2((String)htJSONObject.get("text3"));
b.setTextLine3((String)htJSONObject.get("text4"));
b.setUIIDLine1("MultiLine1");
b.setUIIDLine2("MultiLine2");
b.setUIIDLine3("MultiLine1Right");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
//some action here
}
});
CheckBox cb = new CheckBox();
cb.setName((String)htJSONObject.get("text1"));
String sSomeCondition = (String)htJSONObject.get("Condition");
//If this condition equals "NO" than I want to disable the checkbox
if (sSomeCondition.equals("NO")) {
// I've tried this but it doesn't work good
//cb.setHidden(true);
//cb.setHidden(true, true);
//cb.setVisible(true);
//cb.setEnabled(false);
//TODO - disable checkbox code....???
}
else {
cr.addComponent(cb);
}
cr.addComponent(b);
list.addComponent(cr);
}
When I use "setEnabled(false)" like Chen said in his answer, the checkbox is disabled but it's apperence is the same. I have a disabled style for my checkbox in my theme and I was able to change checkbox background but I want to change the color of the checkbox rectangle.
I tried to do that by adding constant "checkBoxUncheckDisImage" in a theme "Constants" tab and adding another image which would replace checkbox rectangle image but it didn't work.
How do I change the default checkbox image for a disabled checkbox?
setEnabled(false) should do the trick, make sure you have a disabled style for the CheckBox in your theme
I've dynamically created a horizontal scrolling list of labels (with icon and bottom text) within a container in a tab.
However, I cannot seem to bind any action to this Label - I want touch, long press, options(commands), drag, etc
If I use Button instead of Label, I cannot seem to use URLImage to grab the icon from a url and save it to storage and use that as the button icon. It always uses only the placeholder from:
Image img = URLImage.createToStorage(placeholder, counter+"_thumbnail", thumbnailURL, URLImage.RESIZE_SCALE);
How do I grab events on the Labels? Here is a snippet of how I'm adding the labels to the container:
Container c = StateMachine.instance.findFirstListContainer();
for(...){
Label l = new Label();
l.setText(title);
l.setIcon(img);
l.setUIID("listItem");
l.setTextPosition(2);
c.addComponent(l);
}
You should use a Button rather than a Label and invoke the setUIID("Label") method.
The reason why you didn't do this is a separate question/issue: https://groups.google.com/d/msg/codenameone-discussions/5HoDEFjB5II/5dc4iKuYNSYJ