Skip to content

Instantly share code, notes, and snippets.

@codenameone
Created February 26, 2016 20:52
Show Gist options
  • Save codenameone/f5b83373088600b19610 to your computer and use it in GitHub Desktop.
Save codenameone/f5b83373088600b19610 to your computer and use it in GitHub Desktop.
Simple sample of using the Codename One glass pane
Form hi = new Form("Glass Pane", new BoxLayout(BoxLayout.Y_AXIS));
Style s = UIManager.getInstance().getComponentStyle("Label");
s.setFgColor(0xff0000);
s.setBgTransparency(0);
Image warningImage = FontImage.createMaterial(FontImage.MATERIAL_WARNING, s).toImage();
TextField tf1 = new TextField("My Field");
tf1.getAllStyles().setMarginUnit(Style.UNIT_TYPE_DIPS);
tf1.getAllStyles().setMargin(5, 5, 5, 5);
hi.add(tf1);
hi.setGlassPane((g, rect) -> {
int x = tf1.getAbsoluteX() + tf1.getWidth();
int y = tf1.getAbsoluteY();
x -= warningImage.getWidth() / 2;
y += (tf1.getHeight() / 2 - warningImage.getHeight() / 2);
g.drawImage(warningImage, x, y);
});
hi.show();
@codenameone
Copy link
Author

Sample usage of the glasspane functionality of Form.

From the Codename One project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment