1

I tried using browser component.set width/height and its not working, the component is extremely small to the point where its not visible, I only tested it by clicking on it and hearing audio.

BrowserComponent browser = new BrowserComponent();
         browser.setHeight(1000);
         browser.setWidth(1000);

browser.setURL("https://www.youtube.com/embed/dV9fKsjkJDQ/");

bachq22
  • 21
  • 2

1 Answers1

1

You can't set the size of a component in Codename One. You need to use layout managers to position it. Otherwise when you rotate the device or run on a smaller/larger device things won't appear correctly.

Since a browser is scrollable and contains variable data its size is non-deterministic so you should place it in the center of a border layout e.g.:

Form myForm = new Form("Browser", new BorderLayout());
BrowserComponent browser = new BrowserComponent();
myForm.add(BorderLayout.CENTER, browser);
myForm.show();

This will place the browser over the full form regardless of screen size or orientation which is a special behavior of the CENTER position.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Thank you, I have tried using this method but for some reason its positions everything in a small section in the top side of the screen, the only way I got it to work is using BorderLayout.OVERLAY, anyways should border layout be used to position everything ? labels/images etc ? or should I use padding ? – bachq22 May 15 '21 at 16:39
  • If you use this exact code center will work correctly. I'm guessing you made other changes. No you position other things using different layout managers and by nesting layout managers into one another. If you give a specific example of the UI you're trying to build I can give you a specific example of the way it should look in terms of layouts. – Shai Almog May 16 '21 at 01:42
  • thank you, @shai almog is there a way to contact you privately ? im progressing in developing my app but slowly, I have a deadline , and a few more questions that I cant find any answers on online.. – bachq22 May 16 '21 at 02:44
  • Sure. We provide email support in pro or higher subscription levels on the website – Shai Almog May 17 '21 at 03:27