Created
February 26, 2016 20:52
-
-
Save codenameone/f5b83373088600b19610 to your computer and use it in GitHub Desktop.
Simple sample of using the Codename One glass pane
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage of the glasspane functionality of Form.
From the Codename One project