Shikhar13 / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

Image not center #254

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The following code forms a splash screen. The image shown is 70x70. the screen 
is much bigger than the image size. With the following code the image is nearly 
center - out by a pixel. The reason for this is because the framework 
calculates a scrollbar in. Now obviously if I'm going to make a splash screen I 
dont want a scrollbar. It would make sense for me that the framework only 
calculates a scrollbar if the form's content height merrits a scrollbar.

This code makes a 1 pixel error:
Label lbl = new Label(Image.createImage("/splash.png"));
lbl.setGap(0);      // very important!
Style style = lbl.getStyle();               style.setBgColor(Colors.BOZZAPALEWHITE);
style.setAlignment(Component.CENTER);

Form form = new Form();             form.getStyle().setBgColor(Colors.BOZZAPALEWHITE);
form.setLayout(new BorderLayout());
form.addComponent(BorderLayout.CENTER, lbl);
form.show();

This code fixes that error:
Label lbl = new Label(Image.createImage("/splash.png"));
lbl.setGap(0); // very important!
Style style = lbl.getStyle();               style.setBgColor(Colors.BOZZAPALEWHITE);
style.setAlignment(Component.CENTER);

Form form = new Form();
form.setScrollable(false);  // very 
important!          form.getStyle().setBgColor(Colors.BOZZAPALEWHITE);
form.setLayout(new BorderLayout());
form.addComponent(BorderLayout.CENTER, lbl);
form.show();

The same problem is visible with your InfiniteProgress class. unfortunately 
doing d.setScollable(false) in the public Dialog showInifiniteBlocking() {  
call does not fix this. I will have to spend another day debugging this.

Original issue reported on code.google.com by jkoo...@gmail.com on 12 Jul 2012 at 9:14

GoogleCodeExporter commented 9 years ago
Had a little bug and so I dont have the problem in the dialogs! bug still 
persist for form.

Original comment by jkoo...@gmail.com on 12 Jul 2012 at 11:26

GoogleCodeExporter commented 9 years ago
Also why not add a Image Component. I have to constantly add lbl.setGap(0) and 
the drawing sequence of a label with only an image is over complicated.

Original comment by jkoo...@gmail.com on 12 Jul 2012 at 11:27

GoogleCodeExporter commented 9 years ago
The bug should be: When drawing a label that has no text the gap property 
should be ignored both for preferred size and drawing.

Original comment by shai.almog on 12 Jul 2012 at 2:32