I'm setting buttons, textfields and a picture so that there is a perfect looking on simulator IPhone6.
Then I put it on a real IPhone 6, there are some differences.
The picture isn't central, one button is half outside.
I program it by hand with no gui builder.
What is the best way, to set buttons, labels, textfields ... so that they are
correctly placed on hardware?
here my sample code:
Form dlgpass = new Form("");
dlgpass.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Image img2;
try {
img2 = Image.createImage("/xz.jpg");
Container cco2 = BoxLayout.encloseX();
Label llc1 = new Label(" ");
Label llc2 = new Label(" ");
cco2.getStyle().setMarginBottom(50);
cco2.getStyle().setMarginTop(20);
cco2.add(llc1).add(img2).add(llc2);
dlgpass.add(cco2);
Label ll4 = new Label(" ");
Label ll5 = new Label(" ");
Container cco3 = BoxLayout.encloseX();
Label llc3 = new Label(„test");
cco3.getStyle().setMarginTop(100);
cco3.add(ll4).add(llc3).add(ll5);
Container cco4 = BoxLayout.encloseX();
TextField pa = new TextField("", "Password", 16, TextField.PASSWORD);
Label ll6 = new Label(" ");
Label ll7 = new Label(" ");
cco4.getStyle().setMarginTop(60);
cco4.add(ll6).add(pa).add(ll7);
dlgpass.add(cco4);
Button logi = new Button(" login ");
logi.addActionListener((e) -> chlogi(pa.getText(),ce));
Label ll1 = new Label(" ");
Label ll2 = new Label(" ");
Container cco1 = BoxLayout.encloseX();
cco1.getStyle().setMarginTop(60);
cco1.add(ll1).add(logi).add(ll2);
dlgpass.add(cco1);
The picture is 629x810 pixels with 24bit color.
This is a Splashscreen to login.
The pictures:
EDIT
Chen, this is what I tried. Is it what you meant?
Form dlgpass = new Form("", new BorderLayout());
Image img2;
img2 = Image.createImage("/xx.jpg");
ScaleImageLabel simg = new ScaleImageLabel(img2);
dlgpass.add(BorderLayout.CENTER, simg);
Container cco = new Container(new BorderLayout());
TextField pa = new TextField("", "Password", 16, TextField.PASSWORD);
cco.addComponent(BorderLayout.NORTH,pa);
FlowLayout flow = new FlowLayout(Component.CENTER);
flow.setValign(Component.BOTTOM);
Container cco1 = new Container(flow);
Button logi = new Button(" login ");
logi.addActionListener((e) -> chlogi(pa.getText(),ce));
cco1.addComponent(logi);
cco.addComponent(BorderLayout.SOUTH,cco1);
dlgpass.addComponent(BorderLayout.SOUTH,cco);
Avoid spaces, empty labels, setting margins on components use layouts to position the components on the From.
In your use case I would probably do something like this:
Form - BorderLayout.
ScaleImageLabel - center
Container(BorderLayout) - south
TextField - north
Container(FlowLayout center) - south
Button
if you need/want to space the components use setUIID() on the Components and in the theme adjust the margins and/or paddings (always use mm)
To understand layout positioning portability check out this video https://www.codenameone.com/how-do-i---positioning-components-using-layout-managers.html on using layout managers effectively.
Also check out Multi-Image which allow images to adapt to various sizes.
Related
I have to implement printing in a WPF application and I have to scale printable content to page visible area.
This is my code:
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog().Value)
{
FixedDocument fixedDocument = new FixedDocument();
Canvas canvas = new Canvas();
PrintCapabilities pc = dialog.PrintQueue.GetPrintCapabilities();
System.Windows.Shapes.Rectangle rc = new System.Windows.Shapes.Rectangle();
rc.Width = pc.PageImageableArea.ExtentWidth;
rc.Height = pc.PageImageableArea.ExtentHeight;
rc.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 0, 0));
canvas.Children.Add(rc);
Canvas.SetLeft(rc, pc.PageImageableArea.OriginWidth);
Canvas.SetTop(rc, pc.PageImageableArea.OriginHeight);
FixedPage fixedPage = new FixedPage();
fixedPage.Width = dialog.PrintableAreaWidth;
fixedPage.Height = dialog.PrintableAreaHeight;
fixedPage.Children.Add(canvas);
PageContent pageContent = new PageContent();
((IAddChild)pageContent).AddChild(fixedPage);
fixedDocument.Pages.Add(pageContent);
dialog.PrintDocument(fixedDocument.DocumentPaginator, "Demo");
}
The red rectangle is set to fill the page printable area.
The problem is the PrintCapabilities.PageImageableArea always returns the same values no matter what paper (Letter, Legal, etc) is selected.
If I run the code and don't change anything in the print dialog (default paper size is Letter) I get the print below:
The red rectangle fills the entire Letter page.
If I run the code and select Legal paper size in the print dialog then I get the print below:
The PrintCapabilities.PageImageableArea property still returns a Letter sized area no matter I selected Legal paper in print dialog.
I tested the code above with "Microsoft Print to PDF" printer which does not have unprintable margins (this is why the red rectangle fills the entire page) but the problem persists also with a physical printer.
What am I doing wrong?
I would like to know create an image collection without using an ImageView. I want to set the image dimensions and then add the image to a label.
final ScaleImageLabel path = new ScaleImageLabel();
final ScaleImageLabel path1 = new ScaleImageLabel();
final ScaleImageLabel path2 = new ScaleImageLabel();
try {
if (landingInfo.getImagePath()!= null) {
Image backgroundImage = Image.createImage(landingInfo.getImagePath());
backgroundImage.scaled(100, 100);
path.setIcon(backgroundImage);
path.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED);
I need to recreate a program similar to whatsapp that can send and receive messages, images videos and audio. I have created a WPF form to show messages that looks like this:
I have a stack panel that contains text bubbles on them. Text messages work fine but if I send an image I want the user to be able to click on the image text bubble and it must become full screen. The image text bubble consists of a label that has a frame in it and then within that frame the image is stored. The label was used since we could resize the label.
However, because the image is done like this dynamically, we cannot seem to register an on-click event on this image bubble. If you have any better ways that we can display the image or how to log this event it would be much appreciated. Here is the method used to add the image.
public void AddMessage_Image(string path, string displayName, int role, string date = "")
{
//Create an image from the path
ImageBrush image = new ImageBrush();
image.ImageSource = new BitmapImage(new Uri(path, UriKind.Absolute));
image.Stretch = Stretch.Uniform;
//Create a frame in which to place the image
Frame fr = new Frame();
fr.Background = image;
fr.MinHeight = 120;
fr.MinWidth = 160;
//Ensure scalabilty of the image
Viewbox vb = new Viewbox();
vb.Child = fr;
vb.Stretch = Stretch.Uniform;
//Place the image in a sizable container
Label lbl = new Label();
lbl.MinHeight = 10;
lbl.MinWidth = 10;
lbl.MaxHeight = 300;
lbl.MaxWidth = 400;
lbl.Content = vb;
if (role == (int) Role.Sender)
lbl.HorizontalAlignment = HorizontalAlignment.Right;
else
lbl.HorizontalAlignment = HorizontalAlignment.Left;
lbl.Background = Brushes.Black;
//Place the image in the chat
chatbox.Children.Add(lbl);
}
i am working on a Mobile project (iPad with iOS 8.0.2);
I want to make clipping of my immage in order to display less from it.
When displaying on PC it works perfectly well, while we test it on the tablet the clipped image is not displayed at all.
Do you have any suggestions
this.background = new createjs.Bitmap('some_image.png');
//create a clipping of drawn image!
var dims = this.background.getBounds();
this.background.sourceRect = new createjs.Rectangle(0, 15, dims.width, dims.height);
this.background.x = 248;
this.background.y = 86;
this.stage.addChild(this.background);
I met the same trouble like this.I have given up using Bitmap to clipping the image. I have found another solution ,here is "
easeljs splitting an image into pieces
".Good luck.
I am working out, the code like this:
var img, stage;
function init() {
//wait for the image to load
img = new Image();
img.onload = handleImageLoad;
img.src = "./res/image.png";
}
function handleImageLoad(evt) {
// create a new stage and point it at our canvas:
stage = new createjs.Stage("canvas");
// create a new Bitmap, and slice out one image from the sprite sheet:
var bmp = new createjs.Bitmap(evt.target).set({x:200, y:200});
bmp.sourceRect = new createjs.Rectangle(916, 101, 84, 84);
//x,y,width,height
stage.addChild(bmp);
stage.update();
}
This is the example:
https://github.com/CreateJS/EaselJS/blob/master/examples/Filters_animated.html
I'm trying to create a simple toolbar in WPF, but the toolbar shows up with no corresponding buttons on it, just a very thin blank white strip. Any idea what I'm doing wrong, or what the recommended procedure is? Relevant code fragments so far:
var tb = new ToolBar();
var b = new Button();
b.Command = comback;
Image myImage = new Image();
myImage.Source = new BitmapImage(new Uri("back.png", UriKind.Relative));
b.Content = myImage;
tb.Items.Add(b);
var p = new DockPanel();
//DockPanel.SetDock(mainmenu, Dock.Top);
DockPanel.SetDock(tb, Dock.Top);
DockPanel.SetDock(sb, Dock.Bottom);
//p.Children.Add(mainmenu);
p.Children.Add(tb);
p.Children.Add(sb);
Content = p;
Without a third child-element for the Dockpanel p, the 'sb' element will fill everything except for the area of tb. The ToolBar will autoSize (its Height) according to its contents.
I suggest adding a simple text button first, to check the overall layout:
var b2 = new Button();
b2.Content = "B2";
tb.Items.Add(b2);
And then investigate what is wrong with the "back.png" image.