Java Code Examples for com.codename1.ui.Form#add()
The following examples show how to use
com.codename1.ui.Form#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BindButtonStateTest.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); Button button1 = new Button("Button 1"); button1.setIconUIID("GrayIcon"); //button1.getIconStyleComponent().getStyle().setFgColor(0xff0000); FontImage.setIcon(button1, FontImage.MATERIAL_INBOX, -1); Button button2 = new Button("Button 2"); button2.bindStateTo(button1); hi.add(new Label("Hi World")); hi.addAll(button1, button2); hi.show(); }
Example 2
Source File: ExecuteAndReturnStringTest.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", new BorderLayout()); final BrowserComponent cmp = new BrowserComponent(); cmp.setPage("<!doctype html><html><body>Hello World</body></html>", null); Button btn = new Button("Get User Agent"); btn.addActionListener(evt->{ ToastBar.showInfoMessage(cmp.executeAndReturnString("navigator.userAgent")); }); hi.add(CENTER, cmp); hi.add(NORTH, btn); hi.show(); }
Example 3
Source File: LayeredLayoutTest2751.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", new LayeredLayout()); //Form hi = new Form("Hi World", BoxLayout.y()); Container[] components = new Container[20]; for (int i=0; i<20; i++) { components[i] = dummyComponent(40, 20); } Container box = FlowLayout.encloseCenter(components); //box.setPreferredW(200); box.setWidth(200); Dimension prefSize = box.getPreferredSize(); box.setPreferredH(prefSize.getHeight()); box.setPreferredW(200); $(box).selectAllStyles() .setBgTransparency(255) .setBgColor(ColorUtil.YELLOW); hi.add(box); ((LayeredLayout)hi.getLayout()).setInsets(box, "auto auto auto auto"); hi.show(); }
Example 4
Source File: TextFieldCaretColorTest2780.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); hi.add(new Label("Hi World")); TextField tf1 = new TextField(); TextField tf2 = new TextField(); TextArea ta1 = new TextArea(); TextArea ta2 = new TextArea(); ta1.setRows(5); ta2.setRows(5); $(tf2, ta2).selectAllStyles() .setBgColor(0x0000ff) .setFgColor(0xffffff) .setBgTransparency(0xff) .setBackgroundType(Style.BACKGROUND_NONE); hi.addAll(tf1, tf2, ta1, ta2); hi.show(); }
Example 5
Source File: PasswordManagerTestCase2741.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form f = new Form("Form 1", BoxLayout.y()); TextField tf1 = new TextField(); tf1.setConstraint(TextField.PASSWORD); f.add(tf1); Button b = new Button("Login"); b.addActionListener(e->{ Form f2 = new Form("F2", BoxLayout.y()); TextField t2 = new TextField(); ComboBox cb = new ComboBox("Red", "Green", "Blue"); f2.addAll(t2, cb); Button b2 = new Button("Submit"); f2.add(b2); f2.show(); }); f.add(b); f.show(); }
Example 6
Source File: JailbreakDetectionSample.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Jailbreak Detection", BoxLayout.y()); Button detect = new Button("Detect Jailbreak"); detect.addActionListener(evt->{ if (JailbreakDetect.isJailbreakDetectionSupported()) { if (JailbreakDetect.isJailbroken()) { Dialog.show("Jailbroken","This device is jailbroken", new Command("OK") ); } else { Dialog.show("Not Jailbroken", "Probably not jailbroken. But can't be 100% sure.", new Command("OK")); } } else { Dialog.show("No Idea", "No support for jailbreak detection on this device.", new Command("OK")); } }); hi.add(detect); hi.show(); }
Example 7
Source File: AutocompleteSample2788.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Popup test", BorderLayout.absolute()); AutoCompleteTextField autocomplete = new AutoCompleteTextField("1", "2", "3", "11", "22", "33"); autocomplete.setMinimumLength(1); Button tapMe = new Button("Tap me leaving the popup opened"); tapMe.addActionListener(l -> { hi.replace(autocomplete, new Label("other content"), null); hi.revalidate(); }); hi.add(BorderLayout.CENTER, autocomplete); hi.add(BorderLayout.NORTH, tapMe); hi.show(); }
Example 8
Source File: TestComponent.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void getComponentAt_int_int_label() { log("Testing getComponentAt(x, y) with label"); int w = Display.getInstance().getDisplayWidth(); int h = Display.getInstance().getDisplayHeight(); Form f = new Form("My Form", new BorderLayout()); Label l = new Label("Hello"); f.add(BorderLayout.CENTER, l); f.show(); TestUtils.waitForFormTitle("My Form", 2000); Component middleComponent = f.getComponentAt(w/2, h/2); assertEqual(l, middleComponent, "Found wrong component"); }
Example 9
Source File: TabIteratorSample2775.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); hi.add(new TextField("Text 1")); Picker p1 = new Picker(); p1.setType(Display.PICKER_TYPE_STRINGS); p1.setStrings("Red", "Green", "Blue", "Orange"); hi.add(p1); hi.add(new TextField("Text 2")); CheckBox enableTabsCheckBox = new CheckBox("Enable Tabbing"); enableTabsCheckBox.setSelected(true); enableTabsCheckBox.addActionListener(e->{ $("*", hi).each(c->{ c.setPreferredTabIndex(enableTabsCheckBox.isSelected() ? 0 : -1); }); }); hi.add(enableTabsCheckBox); hi.show(); }
Example 10
Source File: TestComponent.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private void getComponentAt_int_int_container() { int w = Display.getInstance().getDisplayWidth(); int h = Display.getInstance().getDisplayHeight(); Form f = new Form("My Form", new BorderLayout()); Container l = new Container(); f.add(BorderLayout.CENTER, l); f.show(); TestUtils.waitForFormTitle("My Form", 2000); Component middleComponent = f.getComponentAt(w/2, h/2); assertEqual(l, middleComponent, "Found wrong component"); }
Example 11
Source File: TestComponent.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private void getComponentAt_int_int_nested_focusable_container() { log("Testing getComponentAt(x, y) with layered nesting"); int w = Display.getInstance().getDisplayWidth(); int h = Display.getInstance().getDisplayHeight(); Form f = new Form("My Form", new BorderLayout()); Container bottom = new Container() { @Override protected Dimension calcPreferredSize() { return new Dimension(w, h); } }; bottom.setGrabsPointerEvents(true); bottom.setName("Bottom"); Container top = new Container(new BorderLayout()); top.setFocusable(true); Label content = new Label("Hello"); content.setName("Content"); top.add(BorderLayout.CENTER, content); top.setName("Top"); Container wrapper = new Container(new LayeredLayout()); wrapper.add(bottom).add(top); f.add(BorderLayout.CENTER, wrapper); f.show(); TestUtils.waitForFormTitle("My Form", 2000); Component middleComponent = f.getComponentAt(w/2, h/2); assertEqual(top, middleComponent, "Found wrong component"); }
Example 12
Source File: NativeControlsSample.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void webviewLoginTest() { Form f= new Form("Test Webview Login", new BorderLayout()); String html = "<!doctype html>" + "<html><body><table><tr><td>Username:</td><td><input type='text' autocomplete='username'/></td></tr><tr><td>Password</td>" + "<td><input type='password' autocomplete='current-password'/></td></tr></body></html>"; BrowserComponent c = new BrowserComponent(); c.setPage(html, "https://weblite.ca/"); f.add(BorderLayout.CENTER, c); f.show(); }
Example 13
Source File: CameraKitPickerTest7.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void showAnotherForm(){ Form form = new Form(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_SCALE)); form.setScrollable(false); Container container = new Container(BoxLayout.y()); container.add(new Label("Test", "heading5")); container.add(new Label("", "newLine")); container.add(new Label("", "newLine")); final Picker fromDate = new Picker(); fromDate.setType(Display.PICKER_TYPE_DATE); container.add(new Label("From Date", "heading7")); container.add(fromDate); container.add(new Label("", "newLine")); final Picker toDate = new Picker(); toDate.setType(Display.PICKER_TYPE_DATE); container.add(new Label("To Date", "heading7")); container.add(toDate); Button nextBtn = new Button("Proceed"); nextBtn.setUIID("loginBtn"); nextBtn.addActionListener((ev) -> { DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy"); String fromDateStr = dateFormat.format(fromDate.getDate()); String toDateStr = dateFormat.format(toDate.getDate()); }); container.add(new Label("", "newLine")); container.add(new Label("", "newLine")); container.add(nextBtn); form.add(BorderLayout.CENTER, container); form.show(); }
Example 14
Source File: TextAreaSample.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", new BorderLayout()); TextArea ta = new TextArea(); hi.add(BorderLayout.CENTER, ta); hi.show(); callSerially(()->ta.setText("Some Text")); }
Example 15
Source File: SideMenuTest3086.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if (current != null) { current.show(); return; } Toolbar.setGlobalToolbar(true); Toolbar.setOnTopSideMenu(false); Form hi2 = new Form("Hi2 World", BoxLayout.y()); hi2.add(new Label("Press to show form2")); hi2.add(new Button(new Command("show form2") { @Override public void actionPerformed(ActionEvent evt) { try { Form hi = new Form("form2"); Toolbar tb = hi.getToolbar(); Image icon = theme.getImage("icon.png"); Container topBar = BorderLayout.east(new Label(icon)); topBar.add(BorderLayout.SOUTH, new Label("Cool App Tagline...", "SidemenuTagline")); topBar.setUIID("SideCommand"); tb.addComponentToSideMenu(topBar); tb.addMaterialCommandToSideMenu("Home", FontImage.MATERIAL_HOME, e -> { }); hi.addComponent(new Label("form2 with sidemenu")); //hi.forceRevalidate(); hi.show(); } catch (Exception ex) { Dialog.show("Error", ex.getMessage(), "OK", null); ex.printStackTrace(); } } })); hi2.show(); }
Example 16
Source File: PickerUnresponsiveTest3051.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi110 = new Form("Welcome", new BorderLayout()); TextField textField1 = new TextField("TextField1", "", 20, TextArea.ANY); TextField textField2 = new TextField("TextField2", "", 20, TextArea.ANY); hi110.add(BorderLayout.NORTH, textField1); hi110.add(BorderLayout.CENTER, textField2); hi110.add(BorderLayout.SOUTH, new Picker()); hi110.show(); }
Example 17
Source File: TestParparTranspileError2922.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Test Split", BoxLayout.y()); String text = "Abc-123456-7890"; String[] tokens = split(text, '-'); hi.add(new Label("Original string: " + text)); hi.add(new Label("Token 1: " + tokens[0])); hi.add(new Label("Token 2: " + tokens[1])); hi.show(); }
Example 18
Source File: NullPointerOnEDTSample2992.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); hi.add(new TextField("", "Write here")); hi.show(); }
Example 19
Source File: RTLLayoutAndPadding.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); Label l = new Label("Hi World"); FlowLayout fl = new FlowLayout(); fl.setAlign(CENTER); Container row = new Container(fl); row.add(new Label("Center")); $(row).selectAllStyles() .setPaddingMillimeters(3f) .setBgColor(0x003366).setBorder(RoundBorder.create()); hi.add(row); fl = new FlowLayout(); fl.setAlign(RIGHT); row = new Container(fl); row.add(new Label("Right")); $(row).selectAllStyles() .setPaddingMillimeters(3f) .setBgColor(0x003366).setBorder(RoundBorder.create()); hi.add(row); fl = new FlowLayout(); fl.setAlign(LEFT); row = new Container(fl); row.add(new Label("Left")); $(row).selectAllStyles() .setPaddingMillimeters(3f) .setBgColor(0x003366).setBorder(RoundBorder.create()); hi.add(row); fl = new FlowLayout(); fl.setAlign(CENTER); row = new Container(fl); row.add(new Label("Center")); $(row).selectAllStyles() .setPaddingMillimeters(1f, 2f, 1f, 5f) .setBgColor(0x003366).setBorder(RoundBorder.create()); hi.add(row); hi.show(); }
Example 20
Source File: InterFormContainerSample.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
public void start() { Button sharedButton = new Button("Shared Button"); InterFormContainer cnt = new InterFormContainer(sharedButton); InterFormContainer cnt2 = new InterFormContainer(sharedButton); Toolbar.setGlobalToolbar(true); Form hi = new Form("Transitions", new BorderLayout()); Container c = new Container(BoxLayout.y()); hi.add(BorderLayout.CENTER, c); hi.add(BorderLayout.SOUTH, cnt); Style bg = hi.getContentPane().getUnselectedStyle(); bg.setBgTransparency(255); bg.setBgColor(0xff0000); Button showTransition = new Button("Show"); Picker pick = new Picker(); pick.setStrings("Slide", "SlideFade", "Cover", "Uncover", "Fade", "Flip"); pick.setSelectedString("Slide"); TextField duration = new TextField("10000", "Duration", 6, TextArea.NUMERIC); CheckBox horizontal = CheckBox.createToggle("Horizontal"); pick.addActionListener((e) -> { String s = pick.getSelectedString().toLowerCase(); horizontal.setEnabled(s.equals("slide") || s.indexOf("cover") > -1); }); horizontal.setSelected(true); c.add(showTransition). add(pick). add(duration). add(horizontal); Form dest = new Form("Destination", new BorderLayout()); sharedButton.addActionListener(e -> { if (sharedButton.getComponentForm() == hi) { dest.show(); } else { hi.showBack(); } }); dest.add(BorderLayout.SOUTH, cnt2); bg = dest.getContentPane().getUnselectedStyle(); bg.setBgTransparency(255); bg.setBgColor(0xff); dest.setBackCommand( dest.getToolbar().addCommandToLeftBar("Back", null, (e) -> hi.showBack())); showTransition.addActionListener((e) -> { int h = CommonTransitions.SLIDE_HORIZONTAL; if (!horizontal.isSelected()) { h = CommonTransitions.SLIDE_VERTICAL; } switch (pick.getSelectedString()) { case "Slide": hi.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000))); break; case "SlideFade": hi.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000))); break; case "Cover": hi.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000))); break; case "Uncover": hi.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000))); break; case "Fade": hi.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000))); break; case "Flip": hi.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000))); dest.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000))); break; } dest.show(); }); hi.show(); }