Java Code Examples for com.codename1.ui.Form#addComponent()
The following examples show how to use
com.codename1.ui.Form#addComponent() .
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: Log.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Places a form with the log as a TextArea on the screen, this method can * be attached to appear at a given time or using a fixed global key. Using * this method might cause a problem with further log output * @deprecated this method is an outdated method that's no longer supported */ public static void showLog() { try { String text = getLogContent(); TextArea area = new TextArea(text, 5, 20); Form f = new Form("Log"); f.setScrollable(false); final Form current = Display.getInstance().getCurrent(); Command back = new Command("Back") { public void actionPerformed(ActionEvent ev) { current.show(); } }; f.addCommand(back); f.setBackCommand(back); f.setLayout(new BorderLayout()); f.addComponent(BorderLayout.CENTER, area); f.show(); } catch (Exception ex) { ex.printStackTrace(); } }
Example 2
Source File: Flickr.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
public static Form createMainForm() { Form main = new Form("Flickr tags"); main.setLayout(new BorderLayout()); Toolbar bar = new Toolbar(); main.setToolBar(bar); addCommandsToToolbar(bar); TextArea desc = new TextArea(); desc.setText("This is a Flickr tags demo, the demo uses the Toolbar to arrange the Form Commands.\n\n" + "Select \"Cats\" to view the latest photos that were tagged as \"Cats\".\n\n" + "Select \"Dogs\" to view the latest photos that were tagged as \"Dogs\".\n\n" + "Select \"Search\" to enter your own tags for search."); desc.setEditable(false); main.addComponent(BorderLayout.CENTER, desc); return main; }
Example 3
Source File: AbstractDemoChart.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
protected Form wrap(String title, Component c){ c.getStyle().setBgColor(0xff0000); Form f = new Form(title); f.setLayout(new BorderLayout()); if (isDrawOnMutableImage()) { int dispW = Display.getInstance().getDisplayWidth(); int dispH = Display.getInstance().getDisplayHeight(); Image img = Image.createImage((int)(dispW * 0.8), (int)(dispH * 0.8), 0x0); Graphics g = img.getGraphics(); c.setWidth((int)(dispW * 0.8)); c.setHeight((int)(dispH * 0.8)); c.paint(g); f.addComponent(BorderLayout.CENTER, new Label(img)); } else { f.addComponent(BorderLayout.CENTER, c); } return f; }
Example 4
Source File: ChartsInBoxLayout.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
public ChartsInBoxLayout() { form = new Form("Charts in Box Layout"); form.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); Component chart1 = getTemperatureChart(); chart1.getStyle().setBgColor(0x0); //chart1.setHeight(300); //chart1.setWidth(300); chart1.setPreferredH(500); form.addComponent(chart1); Component chart2 = getCombinedTemperatureChart(); chart2.getStyle().setBgColor(0x0); chart2.setPreferredH(500); //chart2.setHeight(300); //chart2.setWidth(300); form.setScrollableY(true); form.addComponent(chart2); }
Example 5
Source File: PhotoShare.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
private void showMainForm() { final Form photos = new Form("Photos"); photos.setLayout(new BorderLayout()); GridLayout gr = new GridLayout(1, 1); final Container grid = new Container(gr); gr.setAutoFit(true); grid.setScrollableY(true); grid.addPullToRefresh(new Runnable() { public void run() { refreshGrid(grid); } }); grid.addComponent(new InfiniteProgress()); photos.addComponent(BorderLayout.CENTER, grid); photos.removeAllCommands(); photos.setBackCommand(null); photos.addCommand(createPictureCommand(grid)); photos.show(); refreshGrid(grid); }
Example 6
Source File: SignatureComponentDemo.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Signature Component"); hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); hi.add("Enter Your Name:"); hi.add(new TextField()); hi.add("Signature:"); SignatureComponent sig = new SignatureComponent(); sig.addActionListener((evt)-> { System.out.println("The signature was changed"); Image img = sig.getSignatureImage(); // Now we can do whatever we want with the image of this signature. }); hi.addComponent(sig); hi.show(); }
Example 7
Source File: WebSocketsSample.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
void showChat() { Form f= new Form("Chat"); f.setLayout(new BorderLayout()); Container south = new Container(); final TextField tf = new TextField(); Button send = new Button(new Command("Send") { @Override public void actionPerformed(ActionEvent evt) { if (sock.getReadyState() == WebSocketState.OPEN) { sock.send(tf.getText()); tf.setText(""); } else { Dialog.show("", "The socket is not open", "OK", null); showLogin(); } } }); chatContainer = new Container(); chatContainer.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); south.addComponent(tf); south.addComponent(send); f.addComponent(BorderLayout.SOUTH, south); f.addComponent(BorderLayout.CENTER, chatContainer); f.setFormBottomPaddingEditingMode(true); f.show(); }
Example 8
Source File: PropertyCross.java From codenameone-demos with GNU General Public License v2.0 | 5 votes |
/** * Shows the favorites screen */ void showFavs() { final Form favsForm = new Form("Favourites"); addBackToHome(favsForm); favsForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); if(favoritesList.size() == 0) { favsForm.addComponent(new SpanLabel("You have not added any properties to your favourites")); } else { // this is really trivial we just take the favorites and show them as a set of buttons for(Map<String, Object> c : favoritesList) { MultiButton mb = new MultiButton(); final Map<String, Object> currentListing = c; String thumb_url = (String)currentListing.get("thumb_url"); String guid = (String)currentListing.get("guid"); String price_formatted = (String)currentListing.get("price_formatted"); String summary = (String)currentListing.get("summary"); mb.setIcon(URLImage.createToStorage(placeholder, guid, thumb_url, URLImage.RESIZE_SCALE_TO_FILL)); mb.setTextLine1(price_formatted); mb.setTextLine2(summary); mb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { showPropertyDetails(favsForm, currentListing); } }); favsForm.addComponent(mb); } } favsForm.show(); }
Example 9
Source File: NestedTabsTest3023.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form f = new Form("custom tabs", new BorderLayout()); Tabs outerTabs = new Tabs(); Tabs tabs = new Tabs(); tabs.addTab("inner1", new Label("content1")); tabs.addTab("inner2", new Label("content2")); tabs.addTab("inner3", new Label("content3")); Container tabsCont = tabs.getTabsContainer(); TableLayout newLayout = new TableLayout(1, 2); tabsCont.getComponentAt(0).setHidden(true); tabsCont.setLayout(newLayout); newLayout.addLayoutComponent(newLayout.cc(0,0).widthPercentage(50), tabsCont.getComponentAt(1), tabsCont); newLayout.addLayoutComponent(newLayout.cc(0,1).widthPercentage(50), tabsCont.getComponentAt(2), tabsCont); outerTabs.addTab("outer1", new Container()); outerTabs.addTab("outer2", tabs); f.addComponent(BorderLayout.CENTER, outerTabs); f.show(); }
Example 10
Source File: SetBrowserURLWithJarUrlSample.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form wform = new Form("wform", new BorderLayout()); final BrowserComponent browser = new BrowserComponent(); browser.setURL("jar:///index.html"); wform.addComponent(BorderLayout.CENTER, browser); wform.show(); }
Example 11
Source File: CodenameOneComponentWrapper.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public CodenameOneComponentWrapper(com.codename1.ui.Component codenameOneCmp, boolean forceShow) { this.codenameOneCmp = codenameOneCmp; if(codenameOneCmp instanceof Label) { ((Label)codenameOneCmp).setLegacyRenderer(true); } if(codenameOneCmp.getParent() == null) { if(!(codenameOneCmp instanceof Form)) { Form dummy = new Form("") { @Override protected boolean shouldPaintStatusBar() { return false; } @Override protected Component createStatusBar() { return new com.codename1.ui.Container(); } }; dummy.getTitleArea().setPreferredSize(new com.codename1.ui.geom.Dimension(0, 0)); dummy.setLayout(new com.codename1.ui.layouts.BorderLayout()); dummy.addComponent(com.codename1.ui.layouts.BorderLayout.CENTER, codenameOneCmp); dummy.setWidth(1000); dummy.setHeight(1000); dummy.layoutContainer(); if(forceShow || com.codename1.ui.Display.getInstance().getCurrent() == null) { dummy.show(); } } else { ((Form)codenameOneCmp).layoutContainer(); if(com.codename1.ui.Display.getInstance().getCurrent() == null) { if(codenameOneCmp instanceof com.codename1.ui.Dialog) { ((com.codename1.ui.Dialog)codenameOneCmp).showModeless(); } else { ((Form)codenameOneCmp).show(); } } } } }
Example 12
Source File: GameCanvasImplementation.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Start media playback implicitly setting the component to visible */ public void play() { if(nativePlayer && curentForm == null){ curentForm = Display.getInstance().getCurrent(); Form f = new Form(); f.setLayout(new BorderLayout()); f.addComponent(BorderLayout.CENTER, new MediaPlayer(this)); f.show(); } player.play(); }
Example 13
Source File: MapsDemo.java From codenameone-demos with GNU General Public License v2.0 | 5 votes |
private void showMeOnMap() { Form map = new Form("Map"); map.setLayout(new BorderLayout()); map.setScrollable(false); final MapComponent mc = new MapComponent(); putMeOnMap(mc); mc.zoomToLayers(); map.addComponent(BorderLayout.CENTER, mc); map.getToolbar().addCommandToLeftBar(new MapsDemo.BackCommand()); map.setBackCommand(new MapsDemo.BackCommand()); map.show(); }
Example 14
Source File: PhotoShare.java From codenameone-demos with GNU General Public License v2.0 | 5 votes |
private void showLoginForm() { Form login = new Form("Login"); BorderLayout bl = new BorderLayout(); bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE); ComponentGroup loginDetails = new ComponentGroup(); TextField displayName = new TextField(); displayName.setHint("Display Name"); loginDetails.addComponent(displayName); final TextField email = new TextField(); email.setHint("E-Mail"); loginDetails.addComponent(email); Button send = new Button("Send Verification"); loginDetails.addComponent(send); send.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { onSendAction(email); } }); login.setLayout(bl); login.addComponent(BorderLayout.CENTER, loginDetails); login.show(); }
Example 15
Source File: ClockDemo.java From codenameone-demos with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Clock Demo"); AnalogClock clock = new AnalogClock(); hi.setLayout(new BorderLayout()); hi.addComponent(BorderLayout.CENTER, clock); clock.start(); hi.show(); }
Example 16
Source File: SocialChat.java From codenameone-demos with GNU General Public License v2.0 | 5 votes |
private void createMorphEffect(Label titleLabel) { // animate the components out of the previous form if we are coming in from the login form Form parent = Display.getInstance().getCurrent(); if(parent.getUIID().equals("MainForm")) { for(Component cmp : parent.getContentPane()) { cmp.setX(parent.getWidth()); } // moves all the components outside of the content pane to the right while fading them out over 400ms parent.getContentPane().animateUnlayoutAndWait(400, 0); parent.getContentPane().removeAll(); // we can't mutate a form into a component in another form so we need to convert the background to an image and then morph that // this is especially easy since we already removed all the components Label dummy = new Label(); dummy.setShowEvenIfBlank(true); dummy.setUIID("Container"); dummy.setUnselectedStyle(new Style(parent.getUnselectedStyle())); parent.setUIID("Form"); // special case to remove status bar on iOS 7 parent.getTitleArea().removeAll(); parent.setLayout(new BorderLayout()); parent.addComponent(BorderLayout.CENTER, dummy); parent.revalidate(); // animate the main panel to the new location at the top title area of the screen dummy.setName("fullScreen"); titleLabel.setName("titleImage"); parent.setTransitionOutAnimator(MorphTransition.create(1100).morph("fullScreen", "titleImage")); } }
Example 17
Source File: SocialChat.java From codenameone-demos with GNU General Public License v2.0 | 5 votes |
private void showLoginForm() { Form loginForm = new Form(); loginForm.getTitleArea().setUIID("Container"); loginForm.setLayout(new BorderLayout()); loginForm.setUIID("MainForm"); Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS)); cnt.setUIID("Padding"); Button loginWithGoogle = new Button("Signin with Google"); loginWithGoogle.setUIID("LoginButtonGoogle"); Button loginWithFacebook = new Button("Signin with Facebook"); loginWithFacebook.setUIID("LoginButtonFacebook"); Style iconFontStyle = UIManager.getInstance().getComponentStyle("IconFont"); loginWithFacebook.setIcon(FontImage.create(" \ue96c ", iconFontStyle)); loginWithGoogle.setIcon(FontImage.create(" \ue976 ", iconFontStyle)); cnt.addComponent(loginWithGoogle); cnt.addComponent(loginWithFacebook); loginWithGoogle.addActionListener((e) -> { Dialog.show("Test", "Test", "OK", null); tokenPrefix = "google"; Login gc = GoogleConnect.getInstance(); gc.setScope("profile email https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me"); gc.setClientId("1013232201263-lf4aib14r7g6mln58v1e36ibhktd79db.apps.googleusercontent.com"); gc.setRedirectURI("https://www.codenameone.com/oauth2callback"); gc.setClientSecret("uvu03IXOhx9sO8iPcmDfuX3R"); doLogin(gc, new GoogleData(), false); }); loginWithFacebook.addActionListener((e) -> { tokenPrefix = "facebook"; Login fb = FacebookConnect.getInstance(); fb.setClientId("739727009469185"); fb.setRedirectURI("http://www.codenameone.com/"); fb.setClientSecret("4c4a7df81a8e9ab29ac4e38e6b9e4eb1"); doLogin(fb, new FacebookData(), false); }); loginForm.addComponent(BorderLayout.SOUTH, cnt); loginForm.show(); }
Example 18
Source File: SetPageURLHierarchyTest.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
public void start() { if(current != null){ current.show(); return; } Form wform = new Form("wform", new BorderLayout()); final BrowserComponent browser = new BrowserComponent(); try { browser.setURLHierarchy("/Page.html"); } catch (IOException ex) { Dialog.show("Error", "cannot set URL." + "\nError: " + ex.toString(), "OK", null); } wform.addComponent(BorderLayout.CENTER, browser); wform.show(); }
Example 19
Source File: Poker.java From codenameone-demos with GNU General Public License v2.0 | 4 votes |
/** * The splash screen is relatively bare bones. Its important to have a splash screen for iOS * since the build process generates a screenshot of this screen to speed up perceived performance */ public void showSplashScreen() { final Form splash = new Form(); // a border layout places components in the center and the 4 sides. // by default it scales the center component so here we configure // it to place the component in the actual center BorderLayout border = new BorderLayout(); border.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE); splash.setLayout(border); // by default the form's content pane is scrollable on the Y axis // we need to disable it here splash.setScrollable(false); Label title = new Label("Poker Ace"); // The UIID is used to determine the appearance of the component in the theme title.setUIID("SplashTitle"); Label subtitle = new Label("By Codename One"); subtitle.setUIID("SplashSubTitle"); splash.addComponent(BorderLayout.NORTH, title); splash.addComponent(BorderLayout.SOUTH, subtitle); Label as = new Label(cards.getImage("as.png")); Label ah = new Label(cards.getImage("ah.png")); Label ac = new Label(cards.getImage("ac.png")); Label ad = new Label(cards.getImage("ad.png")); // a layered layout places components one on top of the other in the same dimension, it is // useful for transparency but in this case we are using it for an animation final Container center = new Container(new LayeredLayout()); center.addComponent(as); center.addComponent(ah); center.addComponent(ac); center.addComponent(ad); splash.addComponent(BorderLayout.CENTER, center); splash.show(); splash.setTransitionOutAnimator(CommonTransitions.createCover(CommonTransitions.SLIDE_VERTICAL, true, 800)); // postpone the animation to the next cycle of the EDT to allow the UI to render fully once Display.getInstance().callSerially(new Runnable() { public void run() { // We replace the layout so the cards will be laid out in a line and animate the hierarchy // over 2 seconds, this effectively creates the effect of cards spreading out center.setLayout(new BoxLayout(BoxLayout.X_AXIS)); center.setShouldCalcPreferredSize(true); splash.getContentPane().animateHierarchy(2000); // after showing the animation we wait for 2.5 seconds and then show the game with a nice // transition, notice that we use UI timer which is invoked on the Codename One EDT thread! new UITimer(new Runnable() { public void run() { showGameUI(); } }).schedule(2500, false, splash); } }); }
Example 20
Source File: SocialChat.java From codenameone-demos with GNU General Public License v2.0 | 4 votes |
/** * Shows the form containing the list of contacts we can chat with */ void showContactsForm(UserData data) { listenToMessages(); Form contactsForm = new Form("Contacts"); contactsForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); // the toolbar is created into a layer on the content pane. This allows us to render behind it and leave it semi transparent Toolbar tb = new Toolbar(true); // we want the title area to be transparent so it won't get in the way contactsForm.getTitleArea().setUIID("Container"); // folds the toolbar automatically as we scroll down, shows it if we scroll back up tb.setScrollOffUponContentPane(true); contactsForm.setToolBar(tb); // we want the image behind the toolbar to stretch and fit the entire screen and leave no margin Label titleLabel = new Label(" "); Style titleLabelStyle = titleLabel.getUnselectedStyle(); titleLabelStyle.setBgImage(theme.getImage("social-chat-tutorial-image-top.jpg")); titleLabelStyle.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL); titleLabelStyle.setPadding(tb.getPreferredH(), tb.getPreferredH(), tb.getPreferredH(), tb.getPreferredH()); titleLabelStyle.setPaddingUnit(Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS); titleLabelStyle.setMargin(0, 0, 0, 0); contactsForm.addComponent(titleLabel); // the behavior of the title is rather complex so we extract it to a separate method tb.setTitleComponent(createTitleComponent(contactsForm)); InfiniteProgress ip = new InfiniteProgress(); contactsForm.addComponent(ip); loadContacts(data, ip, contactsForm.getContentPane()); // creates the morph and other animations from the main form to the second form of the app createMorphEffect(titleLabel); contactsForm.show(); showPendingMessages(contactsForm); }