I'm facing an issue with iOS.
I have an App who works perfectly on Android. I build it for Android Debug and when i try to show my form, i got an IndexOutOfBoundsException
Here is my code :
package com.idenovia.calendovia.form;
public class FichePro extends Form {
public static Site site;
public static Boolean isFavorite = false;
public static List<Performance> performances = new ArrayList<Performance>();
public static Long canContactTakeEvent;
public FichePro(final int idPro,final String searchWho, final List<Site> savedSites){
try {
Dialog ip = new InfiniteProgress().showInifiniteBlocking();
ip.getContentPane().getStyle().setBgTransparency(0, true);
ip.getContentPane().getComponentAt(0).getStyle().setBgTransparency(0, true);
Map<String,Object> result;
if(CalendoviaApp.isConnected ==1 && CalendoviaApp.customer.getId() != 0)
result = AccessSite.getSiteFromId(idPro,CalendoviaApp.customer.getId());
else
result = AccessSite.getSiteFromId(idPro,0);
if(result.containsKey("sites")){
site = (Site) result.get("sites");
}else{
site = null;
}
if(result.containsKey("performances")){
performances = (List<Performance>) result.get("performances");
}else{
performances = null;
}
if(result.containsKey("canContactTakeEvent")){
canContactTakeEvent = (Long) result.get("canContactTakeEvent");
}else{
canContactTakeEvent = null;
}
ip.dispose();
} catch (Exception e1) {
e1.printStackTrace();
}
/*
* Form theming and configuring
*/
if(site != null)
setTitle("Dr. "+site.getSiteYou().getShowname());
else{
SearchList searchList = new SearchList(searchWho,"",savedSites);
searchList.show();
}
Container content = new Container(new BoxLayout(BoxLayout.Y_AXIS));
content.setUIID("ctrContent");
setLayout(new BorderLayout());
setTransitionInAnimator(CommonTransitions.createFade(200));
final Font fnt = Font.createTrueTypeFont("CALENDOVIA_APP", "CALENDOVIA_APP.ttf");
Container ctrPhoto = new Container(new BorderLayout());
ctrPhoto.setUIID("ctrPhoto");
// try {
Image image = CalendoviaApp.res.getImage("placeholderProvider").scaled((int)(Display.getInstance().getDisplayWidth()*0.25),(int)(Display.getInstance().getDisplayWidth()*0.25));
for (Site favoris : CalendoviaApp.favorites) {
if(favoris.getId().equals(site.getId())){
isFavorite = true;
}
}
final CheckBox favButton2 = new CheckBox();
final Button favButton = new Button();
if(isFavorite){
favButton.setIcon(FontImage.createFixed("\ue900", fnt, 0x2995d0,(int)(Display.getInstance().getDisplayWidth()*0.2), (int)(Display.getInstance().getDisplayWidth()*0.2)));
}else{
favButton.setIcon(FontImage.createFixed("\ue931", fnt, 0x2995d0,(int)(Display.getInstance().getDisplayWidth()*0.2), (int)(Display.getInstance().getDisplayWidth()*0.2)));
}
favButton.setTextPosition(Component.BOTTOM);
favButton.getStyle().setBgTransparency(0,true);
favButton.getPressedStyle().setBgTransparency(0,true);
favButton.getDisabledStyle().setBgTransparency(0,true);
favButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if(isFavorite){
do some stuff like seticon or network access
}else{
do some stuff too
}
}
});
ctrPhoto.add(BorderLayout.WEST, image);
ctrPhoto.add(BorderLayout.EAST, favButton);
Container ctrglobalInfosFichePro = new Container(new BoxLayout(BoxLayout.Y_AXIS));
ctrglobalInfosFichePro.setScrollVisible(false);
ctrglobalInfosFichePro.setScrollableY(true);
ctrglobalInfosFichePro.setUIID("ctrglobalInfosFichePro");
//First Part
Container ctrglobalInfosFirstPart = new Container(new BoxLayout(BoxLayout.Y_AXIS));
ctrglobalInfosFirstPart.setScrollableY(false);
ctrglobalInfosFirstPart.setUIID("ctrglobalInfosFirstPart");
Label lblProviderName = new Label("Dr "+site.getSiteYou().getShowname());
lblProviderName.setUIID("lblNameProvider");
ctrglobalInfosFichePro.add(lblProviderName);
try{
Label lblProviderSpe = new Label(new SectorConvert().getValue(site.getSiteYou().getSectorfirst().intValue()).toString());
lblProviderSpe.setUIID("lblSpeProvider");
ctrglobalInfosFichePro.add(lblProviderSpe);
}catch(Exception e){
} if(site.getSiteOption().getCbcard()||site.getSiteOption().getCheckp()||site.getSiteOption().getSpecies()){
Label lblPaiement = new Label("MOYENS DE PAIEMENT");
lblPaiement.setUIID("lblTitleForSpanLabel");
lblPaiement.setVerticalAlignment(Component.CENTER);
String acceptedPaiement ="";
if(site.getSiteOption().getCbcard()){
acceptedPaiement+=" CB /";
}
Label lblAcceptedPaiement = new Label(acceptedPaiement);
ctrglobalInfosFirstPart.add(lblPaiement);
ctrglobalInfosFirstPart.add(lblAcceptedPaiement);
}
//Second Part
Container ctrglobalInfosSecondPart= new Container(new BorderLayout());
if(site.getSiteYou().getPhonepro().trim().length() != 0){
ctrglobalInfosSecondPart.setUIID("ctrglobalInfosFirstPart");
Button btnAppeler = new Button("Appeler");
btnAppeler.setUIID("btnAppelerFichePro");
btnAppeler.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
Display.getInstance().dial(site.getSiteYou().getPhonepro());
}
});
ctrglobalInfosSecondPart.add(BorderLayout.EAST,btnAppeler);
}
ctrglobalInfosFichePro.add(ctrglobalInfosFirstPart);
ctrglobalInfosFichePro.add(ctrglobalInfosSecondPart);
content.add(ctrglobalInfosFichePro);
/*
* Building Form
*/
if(site.getCanaccess()){
Button btnTakeAppointement = new Button("");
btnTakeAppointement.setUIID("");
btnTakeAppointement.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
if(site.getNewcontactblocked()){
if(canContactTakeEvent != null && CalendoviaApp.isConnected==1 && CalendoviaApp.customer.getId() != 0){
switch(canContactTakeEvent.intValue()){
case 0:
FicheProCannotTakeEvent ficheProCannotTakeEvent = new FicheProCannotTakeEvent(site, canContactTakeEvent, savedSites, searchWho,true);
ficheProCannotTakeEvent.show();
break;
case 1:
FicheProRdvSelect ficheProRdvSelect = new FicheProRdvSelect(performances,site, savedSites, searchWho, null);
ficheProRdvSelect.show();
break;
[...]
default:
FicheProCannotTakeEvent ficheProCannotTakeEvent4 = new FicheProCannotTakeEvent(site, new Long(4), savedSites, searchWho,true);
ficheProCannotTakeEvent4.show();
break;
}
}else{
FicheProCannotTakeEvent ficheProCannotTakeEvent = new FicheProCannotTakeEvent(site, new Long(0), savedSites, searchWho,false);
ficheProCannotTakeEvent.show();
}
}
else{
FicheProRdvSelect ficheProRdvSelect = new FicheProRdvSelect(performances,site, savedSites, searchWho, null);
ficheProRdvSelect.show();
}
}
});
addComponent(BorderLayout.SOUTH,btnTakeAppointement);
}else{
Button btnParrainage = new Button("");
btnParrainage.setUIID("btnTakeRdvBig");
btnParrainage.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
Parrainage parrainage = new Parrainage(site, getComponentForm());
parrainage.show();
}
});
addComponent(BorderLayout.SOUTH,btnParrainage);
}
addComponent(BorderLayout.NORTH, ctrPhoto);
addComponent(BorderLayout.CENTER, content);
}
}
I can't find the error where it happens and why...
Thanks for your help
Related
I've an issue while trying to save an image to the Storage in iOS. Image is downloaded but not saved.
The code is:
Form hi = new Form("Toolbar", new BoxLayout(BoxLayout.Y_AXIS));
TreeModel tm = new TreeModel() {
#Override
public Vector getChildren(Object parent) {
String[] files;
if (parent == null) {
files = FileSystemStorage.getInstance().getRoots();
return new Vector<Object>(Arrays.asList(files));
} else {
try {
files = FileSystemStorage.getInstance().listFiles((String) parent);
} catch (IOException err) {
Log.e(err);
files = new String[0];
}
}
String p = (String) parent;
Vector result = new Vector();
for (String s : files) {
result.add(p + s);
}
return result;
}
#Override
public boolean isLeaf(Object node) {
return !FileSystemStorage.getInstance().isDirectory((String) node);
}
};
Command tree = new Command("Show tree") {
#Override
public void actionPerformed(ActionEvent evt) {
Form treeForm = new Form("Tree", new BorderLayout());
Tree t = new Tree(tm) {
#Override
protected String childToDisplayLabel(Object child) {
String n = (String) child;
int pos = n.lastIndexOf("/");
if (pos < 0) {
return n;
}
return n.substring(pos);
}
};
treeForm.add(BorderLayout.CENTER, t);
Command back = new Command("Back") {
#Override
public void actionPerformed(ActionEvent evt) {
hi.showBack();
}
};
Button backButton = new Button(back);
treeForm.add(BorderLayout.SOUTH, backButton);
treeForm.show();
}
};
hi.getToolbar().addCommandToOverflowMenu(tree);
EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(hi.getWidth(), hi.getWidth() / 5, 0xffff0000), true);
String photoURL = "https://awoiaf.westeros.org/images/thumb/9/93/AGameOfThrones.jpg/400px-AGameOfThrones.jpg";
StringBuilder fsPath = new StringBuilder(FileSystemStorage.getInstance().getAppHomePath());
fsPath.append("400px-AGameOfThrones.jpg");
URLImage background = URLImage.createToStorage(placeholder, fsPath.toString(), photoURL);
background.fetch();
Style stitle = hi.getToolbar().getTitleComponent().getUnselectedStyle();
stitle.setBgImage(background);
stitle.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
stitle.setPaddingUnit(Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS);
stitle.setPaddingTop(15);
SpanButton credit = new SpanButton("Link");
credit.addActionListener((e) -> Display.getInstance().execute("https://awoiaf.westeros.org/index.php/A_Game_of_Thrones"));
hi.add(new SpanLabel("A")).
add(new Label("B", "Heading")).
add(credit);
ComponentAnimation title = hi.getToolbar().getTitleComponent().createStyleAnimation("Title", 200);
hi.getAnimationManager().onTitleScrollAnimation(title);
hi.show();
Which was taken from https://www.codenameone.com/javadoc/com/codename1/ui/URLImage.html
The tree is only to see if the image was saved in the Storage.
You are mixing Storage & FileSystemStorage which are very different things see this.
You can use storage which is a flat set of "files" and that's what URLImage.createToStorage does. But then you need to use the Storage API to work with that and it might not be visible in the FileSystemStorage API.
Alternatively you might be looking for URLImage.createToFileSystem().
How can I add a container to a particular swipe tabs based on selected Index value of the tabs dynamically?
Here is a simple example that adds a label to the currently selected tab when a button is pressed:
int compIndex = 1;
public void start() {
if(current != null){
current.show();
return;
}
Form hi = new Form("Hi World", new BorderLayout());
Tabs tabs = new Tabs();
tabs.addTab("Tab 1", BoxLayout.encloseY(new Label("Tab 1")));
tabs.addTab("Tab 2", BoxLayout.encloseY(new Label("Tab 2")));
tabs.addTab("Tab 3", BoxLayout.encloseY(new Label("Tab 3")));
Button btn = new Button("Add To current");
btn.addActionListener(e->{
((Container)tabs.getSelectedComponent()).add("Added Component "+(compIndex++))
.revalidate();
});
hi.add(BorderLayout.CENTER, tabs).add(BorderLayout.SOUTH, btn);
hi.show();
}
Container can be added to tabs as shown in below.
tabs.addSelectionListener(new SelectionListener() {
#Override
public void selectionChanged(int oldSelected, int newSelected) {
addComponent(newSelected)
}
}
void addContainer(int index){
Container container = new Container();
tabs.addComponent(index, container);
}
void addComponent(int newSelected,NamesListBean nameListBean) {
displayContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
displayContainer.removeAll();
for(NamesBeans names:nameListBean.getNamesList()){
displayContainer.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Label name=new Label(names.getNames());
Log.p("names======="+names.getNames());
//displayNamesContainer.removeAll();
//displayNamesContainer.forceRevalidate();
displayContainer.add(name);
}
//getDisplay(displayContainer);
//Container container = new Container();
tabs.addComponent(newSelected, displayContainer);
displayContainer.revalidate();
}
});
public class MaskAndUnMask extends Form{
public MaskAndUnMask(Form current,Resources theme){
this.current=current;
this.theme=theme;
}
public void mask(){
Form hi = new Form("Swipe Tabs", new LayeredLayout());
Style s = UIManager.getInstance().getComponentStyle("Button");
FontImage radioEmptyImage = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_UNCHECKED, s);
FontImage radioFullImage = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_CHECKED, s);
((DefaultLookAndFeel)UIManager.getInstance().getLookAndFeel()).setRadioButtonImages(radioFullImage, radioEmptyImage, radioFullImage, radioEmptyImage);
nameListBean=getSwipeTabsValues(lowerBound,upperBound);
finalRadioList=new ArrayList<String>();
radioList=new ArrayList<RadioButton>();
tabsListName=new ArrayList<String>();
borderLayoutContainer=new Container(new BorderLayout());
radioTypeContainer=new Container();
FlowLayout buttonFlowLayout = new FlowLayout();
buttonFlowLayout.setAlign(Component.CENTER);
radioTypeContainer.setLayout(buttonFlowLayout);
buttonGroup=new ButtonGroup();
displayContainer1=new Container(new BoxLayout(BoxLayout.Y_AXIS));
displayContainer1.setScrollableY(true);
tabs = new Tabs();
divOfRadioButton=totalRecordCount/10;
modOfRadioButton=totalRecordCount%10;
if(modOfRadioButton>0 && modOfRadioButton<9){
totalRadioButton=divOfRadioButton+1;
}else{
totalRadioButton=divOfRadioButton;
}
displayContainer = new Container();
for(i=0;i<totalRadioButton;i++){
displayContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
displayContainer.removeAll();
displayContainer.revalidate();
tabs.addTab("",displayContainer);
tabs.setName("t"+i);
tabs.setTabUIID(tabs.getName());
radioButton =new RadioButton();
radioButton.setName("rbt"+i);
radioTypeContainer.add(radioButton);
finalRadioList.add(radioButton.getName());
tabsListName.add(tabs.getName());
radioList.add(radioButton);
tabIndex0="rbt0";
if(radioList.get(i).getName().equals(tabIndex0)){
radioList.get(i).setSelected(true);
getDisplay(displayContainer);
}
buttonGroup.addAll(radioButton);
}
for(int i=0;i<radioList.size();i++){
radioList.get(i).addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
for(int i=0;i<radioList.size();i++){
radioButtonIndex="t"+buttonGroup.getSelectedIndex();
}
for(int i=0;i<tabsListName.size();i++){
if(radioButtonIndex!=null && radioButtonIndex.equals(tabsListName.get(i))){
tabs.setSelectedIndex(buttonGroup.getSelectedIndex());
}
}
}
});
}
borderLayoutContainer.add(BorderLayout.SOUTH,radioTypeContainer);
tabs.addSelectionListener(new SelectionListener() {
#Override
public void selectionChanged(int oldSelected, int newSelected) {
radioButtonName="rbt"+newSelected;
for(int i=0;i<radioList.size();i++){
if(radioList.get(i).getName().equals(radioButtonName)){
val=newSelected;
if(newSelected==0){
nameListBean = null;
lowerBound=Constants.PAGELOWERBOUND;
upperBound=Constants.PAGEUPPERBOUND;
nameListBean=getSwipeTabsValues(lowerBound,upperBound);
addComponent(newSelected,nameListBean);
radioList.get(i).setSelected(true);
break;
}else{
nameListBean = null;
int val=newSelected;
int multipleVal=val*Constants.PAGEUPPERBOUND+1;
lowerBound=multipleVal;
upperBound=multipleVal+9;
nameListBean=getSwipeTabsValues(lowerBound,upperBound);
addComponent(newSelected,nameListBean);
radioList.get(i).setSelected(true);
break;
}
}else{
radioList.get(i).setSelected(false);
}
}
}
void addComponent(int newSelected,NamesListBean nameListBean) {
displayContainer.removeAll();
for(NamesBeans names:nameListBean.getNamesList()){
displayContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Label name=new Label(names.getNames());
displayContainer.add(name);
}
tabs.addComponent(newSelected, displayContainer);
displayContainer.revalidate();
}
});
displayContainer1.add(tabs);
displayContainer1.add(borderLayoutContainer);
hi.add(displayContainer1);
hi.show();
}
I would like to display DateTime picker in my App, so I'm write below code to display DateTime Picker, every thing is working fine but in Android device date is not displayed properly.
Form dialogtimeForm = new Form("Set time");
dialogtimeForm.setUIID("workersListForm");
if(!Constants.PLATFORMNAME.equals(Display.getInstance().getPlatformName())){
spinner = new DateTimeSpinner(){
#Override
protected Dimension calcPreferredSize() {
return new Dimension(460, 180);
}
};
} else{
spinner = new DateTimeSpinner();
}
spinner.setShowMeridiem(true);
spinner.setMinuteStep(1);
int hours = 0;
int minutes = 0;
boolean showMeridiem = false;
Date date = null;
timeValue = data;
if(timeValue != null && !"".equals(timeValue)){
hours = Util.getHours(timeValue);
minutes = Util.getMinutes(timeValue);
showMeridiem = Util.getAmPm(timeValue);
date = Util.getDate(DBActuallCallDate);
}
if(hours > 12){
hours = hours -12;
showMeridiem = true;
}
spinner.setCurrentHour(hours);
spinner.setCurrentMinute(minutes);
spinner.setCurrentMeridiem(showMeridiem);
spinner.setCurrentDate(date);
dialogtimeForm.add(spinner);
Dialog dialog = new Dialog();
dialog.setDisposeWhenPointerOutOfBounds(true);
commands[0] = new Command(Constants.SETCOMMAND){
#Override
public void actionPerformed(ActionEvent evt) {
int hour = spinner.getCurrentHour();
int minute = spinner.getCurrentMinute();
boolean meridiem = spinner.isCurrentMeridiem();
String time = Util.timeConversion(hour, minute, meridiem);
String workerTime = Util.getFormatedTimeValue(time, spinner.getCurrentDate());
callInField.setText(time);
roasterDao = new RoasterDao();
if(flag.equals(Constants.ACTUALCALLOUTFLAG))
roasterDao.updateActualCallOutTime(workerTime, serialId);
else
roasterDao.updateActualCallInTime(workerTime, serialId);
dialog.dispose();
if(ApplicationScopeBean.dialogShow){
if(flag.equals(Constants.ACTUALCALLOUTFLAG))
Dialog.show("Alert", workerName+Constants.CHECKOUTSUCCESSFULLY+time,"ok",null);
else
Dialog.show("Alert", workerName+Constants.CHECKINSUCCESSFULLY+time,"ok",null);
} else{
if(flag.equals(Constants.ACTUALCALLOUTFLAG))
Toast.makeText(RoasterApp.getContext(), workerName+Constants.CHECKOUTSUCCESSFULLY+time, Toast.LENGTH_LONG).show();
else
Toast.makeText(RoasterApp.getContext(), workerName+Constants.CHECKINSUCCESSFULLY+time, Toast.LENGTH_LONG).show();
}
Container unScheduledWorkerTableContainer = setUnScheduledWorkerTable();
unScheduledWorkerTableContainer.setUIID("unScheduledWorkerTable");
unScheduledWorkerBoxContainer.removeAll();
unScheduledWorkerBoxContainer.add(unScheduledWorkerTableContainer);
unScheduledWorkersForm.revalidate();
}
};
commands[1] = new Command(Constants.CLEARCOMMAND){
#Override
public void actionPerformed(ActionEvent evt) {
Dialog dialog1 = new Dialog();
dialog1.setUIID("listDialog");
String clearCallOutDialog = Constants.CLEARCALLOUTDIALOG;
String clearCallInDialog = Constants.CLEARCALLINDIALOG;
dialog.dispose();
FlowLayout centerLayout = new FlowLayout();
centerLayout.setAlign(Component.CENTER);
centerLayout.setValign(Component.TOP);
Container flowContainer = new Container(centerLayout);
Container boxXAxisLayout = new Container(new BoxLayout(BoxLayout.X_AXIS));
Button okButton = new Button(Constants.OKCOMMAND);
okButton.setUIID("dialogCloseButton");
okButton.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
roasterDao = new RoasterDao();
if(flag.equals(Constants.ACTUALCALLOUTFLAG))
roasterDao.updateActualCallOutTime("", serialId);
else
roasterDao.updateActualCallInTime("", serialId);
callInField.setText("");
dialog1.dispose();
dialog.dispose();
Container unScheduledWorkerTableContainer = setUnScheduledWorkerTable();
unScheduledWorkerTableContainer.setUIID("unScheduledWorkerTable");
unScheduledWorkerBoxContainer.removeAll();
unScheduledWorkerBoxContainer.add(unScheduledWorkerTableContainer);
unScheduledWorkersForm.revalidate();
}
});
Button close = new Button(Constants.CANCELCOMMAND);
close.setUIID("dialogCloseButton");
close.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
dialog1.dispose();
dialog.dispose();
Container unScheduledWorkerTableContainer = setUnScheduledWorkerTable();
unScheduledWorkerTableContainer.setUIID("unScheduledWorkerTable");
unScheduledWorkerBoxContainer.removeAll();
unScheduledWorkerBoxContainer.add(unScheduledWorkerTableContainer);
unScheduledWorkersForm.revalidate();
}
});
boxXAxisLayout.add(okButton);
boxXAxisLayout.add(close);
flowContainer.add(boxXAxisLayout);
dialog1.setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_SCALE));
String dataLabelString = "";
if(flag.equals(Constants.ACTUALCALLOUTFLAG))
dataLabelString = clearCallOutDialog;
else
dataLabelString = clearCallInDialog;
Label dataLabel = new Label(dataLabelString);
dataLabel.setUIID("confirmDialogBody");
dialog1.add(BorderLayout.CENTER, dataLabel);
dialog1.add(BorderLayout.SOUTH, flowContainer);
dialog1.show();
}
};
commands[2] = new Command(Constants.CANCELCOMMAND){
#Override
public void actionPerformed(ActionEvent evt) {
dialog.dispose();
Container unScheduledWorkerTableContainer = setUnScheduledWorkerTable();
unScheduledWorkerTableContainer.setUIID("unScheduledWorkerTable");
unScheduledWorkerBoxContainer.removeAll();
[![enter image description here][1]][1]unScheduledWorkerBoxContainer.add(unScheduledWorkerTableContainer);
unScheduledWorkersForm.revalidate();
}
};
dialog.show("", dialogtimeForm, commands);
please find screenshots.
The Picker API will display native date/time UI on supported platforms. Date, Time, Numbers and Strings are supported on Android but DateTime is only supported on iOS so you are seeing a "fallback" UI.
There is no native equivalent for "DateTime" on Android so you would need
This is my code:
public class InfoPanel extends JPanel{
... ... ...
... ... ...
public InfoPanel(){
... ... ...
... ... ...
MigLayout lManager = new MigLayout();
setLayout(lManager);
add(lblName,new CC().pos("50", "80"));
add(txtName, new CC().pos("90","80").width("170").wrap().gap("r"));
add(lblOccupation,"pos 20 100");
add(txtOccupation,"pos 91 100,w 170,wrap,gap r");
and it has the right output.
but I want to use any built in code for calculate pos() for txtName, txtOccupation.
can anybody help me to do that.
From the image as template:
public class MigLayoutTest {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
new MigLayoutTest().start();
}
});
}
private void start() {
JFrame frame = new JFrame();
Container contentPane = frame.getContentPane();
contentPane.setLayout(new MigLayout("wrap 4, debug", "[][fill, grow 1][][fill, grow 4]", ""));
//Declaration
JLabel nameLabel, employmenLabel, ssnLabel, taxIDLabel;
JTextField nameField, ssnField, taxIDField;
JComboBox<String> employmentBox;
JCheckBox checkbox;
JButton save, cancel, upload;
JPanel imagePlaceholder;
//Initialization
nameLabel = new JLabel("Name");
employmenLabel = new JLabel("Employment");
ssnLabel = new JLabel("Social Security Number");
taxIDLabel = new JLabel("tax ID");
nameField = new JTextField();
ssnField = new JTextField();
taxIDField = new JTextField();
save = new JButton("Save");
cancel = new JButton("Cancel");
upload = new JButton("Upload");
checkbox = new JCheckBox("Checkbox");
imagePlaceholder = new JPanel();
employmentBox = new JComboBox<String>();
//Some editing
imagePlaceholder.setBackground(Color.GREEN);
employmentBox.addItem("Some");
employmentBox.addItem("items");
employmentBox.addItem("to");
employmentBox.addItem("fill");
employmentBox.addItem("this");
//Adding to contentPane
contentPane.add(nameLabel, "alignx right");
contentPane.add(nameField, "");
contentPane.add(ssnLabel, "alignx right");
contentPane.add(ssnField, "");
contentPane.add(employmenLabel, "alignx right");
contentPane.add(employmentBox, "");
contentPane.add(upload, "");
contentPane.add(imagePlaceholder, "spany 3, grow");
contentPane.add(checkbox, "split 2");
contentPane.add(taxIDLabel, "");
contentPane.add(taxIDField, "wrap");
contentPane.add(save, "");
contentPane.add(cancel, "growx 0, wrap");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
I am trying below mention code for download image from server but it's not working and not giving me any error. Please suggest if any thing wrong which i used.When i am accessing URL from browser it's displaying image to me.
int pos;
public void DisplayContent()
{
f = (Form)createContainer(GlobalVariables.Theme, "ContentPageWise");
body = (Container) findByName("Containerbody", f);
Display_Image = new Image[Page_Details.size()];
for(int i=0;i<Page_Details.size();i++)
{
Hashtable<String,String> hash_page = Page_Details.get(i);
Log.p("imagepath:"+hash_page.get("imgPage"));
pos=i;
GetImagesFromserver(hash_page.get("imgPage"));
Container Cpage = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Label pic = new Label();
pic.setIcon(Display_Image[i]);
Cpage.addComponent(pic);
body.addComponent(Cpage);
}
}
void GetImagesFromserver(String Imagepath)
{
//eg. url like this: http://lmsasr.gizmosupport.com/presentation/tele/internet.jpg
ImageDownloadService imageDownloadService =
new ImageDownloadService(Imagepath, actionListener);
InfiniteProgress ip = new InfiniteProgress();
imageDownloadService.setDisposeOnCompletion(ip.showInifiniteBlocking());
NetworkManager.getInstance().addToQueue(imageDownloadService);
}
ActionListener actionListener = new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
NetworkEvent n = (NetworkEvent) evt;
Display_Image[pos] = ((Image)n.getMetaData());
}
};