How to set ImageItems ! ! !

Hi friends,

In my Form i have 2 ImageItems,I want both should be in Center and parallel to each other(Horizontally). For that i used

image1, Item.LAYOUT_LEFT | Item.LAYOUT_CENTER

image2, Item.LAYOUT_RIGHT | Item.LAYOUT_CENTER

Butthey r not taking right places .

Plz tell me what should i do for this so that both Images be in center n llel to eachother.

Best regards

karan

[421 byte] By [karan88a] at [2007-11-26 23:43:27]
# 1
Are both the images of yours equal sizes in terms of width & height?Also, as you must be aware that the arrangement of the items on the screen depends on the device display screen size.~Mohan
itsmohana at 2007-7-11 15:13:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
Hi Mohan,Sizes of both the imageItems are same.Is it any way to solve that issue ! !
karan88a at 2007-7-11 15:13:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
show us some code !
suparenoa at 2007-7-11 15:13:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

*/

public class ListScreen extends Form implements CommandListener,ItemCommandListener{

public MobileClientMIDlet parent;

public static String USERID ;

private Spacer spacer;

MyCustomItem custom=null;

public boolean focused;

private ImageItem timesheetImage;

private ImageItem reportImage;

StringItem strItem = null;

private ImageItem manteamImage,mansoftImage;

Image image=null,image2=null;

private static final Command okCommand = new Command("OK", Command.ITEM, 1);

private static final Command exitCommand = new Command("Exit", Command.EXIT, 3);

private static final Command backCommand = new Command("Back", Command.BACK, 0);

public ListScreen(MobileClientMIDlet parent,String USERID) {

super("");

this.parent=parent;

this.USERID=USERID;

ProjectListForm projectlist=new ProjectListForm(parent,USERID);

try {

image = Image.createImage("/mansoftMobileSolution/images/manteam.JPG");

} catch (Exception e) {e.getMessage();}

manteamImage = new ImageItem("", image, Item.LAYOUT_TOP |Item.LAYOUT_CENTER,

"", Item.PLAIN);

append(manteamImage);

strItem=new StringItem("Welcome Mr.",USERID);

strItem.setLayout(Item.LAYOUT_CENTER | Item.LAYOUT_TOP | Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_NEWLINE_BEFORE);

append(strItem);

spacer = new Spacer(0,10);

spacer.setLayout(Item.LAYOUT_NEWLINE_BEFORE);

append(spacer);

boolean firstTime = true;

if (firstTime) {

// Loads the image

Image image1=null,image2 = null;

try {

image1 = Image.createImage("/mansoftMobileSolution/images/time.jpg");

} catch (Exception e) {}

// Loads the image

try {

image2 = Image.createImage("/mansoftMobileSolution/images/report.jpg");

} catch (Exception e) {}

//Creates a HYPERLINK image item

timesheetImage = new ImageItem("timesheet", image1, Item.LAYOUT_LEFT |Item.LAYOUT_DEFAULT ,

"", Item.HYPERLINK);

//spacer = new Spacer(0, 20);

//append(spacer);

//Creates a HYPERLINK image item

reportImage = new ImageItem("report", image2, Item.LAYOUT_RIGHT |Item.LAYOUT_DEFAULT,

"", Item.HYPERLINK);

append(timesheetImage);

spacer = new Spacer(0, 30);

append(spacer);

append(reportImage);

spacer = new Spacer(0,0);

spacer.setLayout(Item.LAYOUT_NEWLINE_BEFORE);

append(spacer);

try {

image2 = Image.createImage("/mansoftMobileSolution/images/mansoft.png");

} catch (Exception e) {}

//append("Developed by ");

mansoftImage = new ImageItem("Developed by", image2, Item.LAYOUT_BOTTOM |Item.LAYOUT_CENTER,

"", Item.PLAIN);

append(mansoftImage);

addCommand(backCommand);

addCommand(exitCommand);

//Specifies commands for HYPERLINK and BUTTON ImageItems

timesheetImage.setDefaultCommand(okCommand);

reportImage.setDefaultCommand(okCommand);

// Registers the CommandListener

setCommandListener(this);

timesheetImage.setItemCommandListener(this);

reportImage.setItemCommandListener(this);

firstTime = false;

}

}

best regard

karan

karan88a at 2007-7-11 15:13:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5
I believe you need to append "timesheetImage " & "reportImage". Why are you appending spacer object with 30 pixels inbetween both the images? Basically you can't say 30 pixels that needs to be dynamically computed based on the device display size.~Mohan
itsmohana at 2007-7-11 15:13:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

to solve your problem, you can:

1- create your 2 imageItems

2- get the width of two of them

3- create a Spacer which width is:

int spacerWidth=widthScreen-(imgItem1.width+imgItem2.width);

append all to the form...

it may work !

suparenoa at 2007-7-11 15:13:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...