为什么在这种情况下不显示对话框?

发布于 2024-12-11 21:11:29 字数 15944 浏览 0 评论 0原文

我想在单击我创建的用户定义组件时显示一个Dialog:我将其类名命名为ListBox。我想用我的用户定义组件模拟一个 LWUIT ComboBox ,该组件将接受空白区域;因为 LWUIT ComboBox 不接受空白区域。

问题是,当我的 ListBox 位于某个坐标,使其下方没有更多空间来显示 Dialog 时,Dialog 就不会所示;但如果下面有更多空间,则会显示Dialog

这是未显示 Dialog 时捕获的图像:

在此处输入图像描述

在捕获的图像中图像用户定义的 ListBox 是手机屏幕底部两个 Button 上方的组件。

下面是代码:

public class ListBox extends Container implements ActionListener
{
    private Container cListBox = new Container(new BorderLayout());
    private Label[] tLabel;
    private int[] tLabelW;
    private int largestLabelW;
    private Label libelle = new Label();
    private Label arrow = new Label((MenuPrincipalForm.r).getImage("listboxarrow"));
    private int preferredWidth, preferredHeight, screenWidth, screenHeight;
    private Vector vData = new Vector();
    private final int leftPadding = 3;
    private CListCellListBox listRenderer;
    private List list;
    private Dialog dialog;
    private String selectedData;

    public ListBox(String[] lData, int prefHeight, int formWidth, int formHeight, int topMargin, int bottomMargin)
    {
        super(new FlowLayout(Component.CENTER));
        setFocusable(true);
        screenWidth = formWidth;
        screenHeight = formHeight;
        tLabel = new Label[lData.length + 1];
        tLabelW = new int[lData.length + 1];
        for (int i = 0 ; i < lData.length + 1 ; i++)
        {
            if (i < lData.length)
            {
                vData.addElement(new String(lData[i]));
                tLabel[i] = new Label(lData[i]);
                tLabelW[i] = tLabel[i].getPreferredW();
            }
            else
            {
                vData.addElement(new String(""));
                tLabel[i] = new Label("");
                tLabelW[i] = 0;
            }
        }
        largestLabelW = Comparator.max(tLabelW);
        preferredWidth = leftPadding + largestLabelW + arrow.getPreferredW();
        preferredHeight = prefHeight - 2 ;
        selectedData = String.valueOf(vData.lastElement());
        libelle.setText(String.valueOf(vData.lastElement()));
        libelle.setTextPosition(Label.LEFT);
        libelle.setPreferredW(preferredWidth);
        libelle.setPreferredH(preferredHeight);
        arrow.setAlignment(Label.CENTER);
        arrow.setPreferredH(preferredHeight);
        listRenderer = new CListCellListBox(false);
        list = (new CList(vData, false)).createList(listRenderer, this);
        list.setItemGap(0);
        list.setSelectedIndex(vData.indexOf(vData.lastElement()));
        list.getUnselectedStyle().setPadding(0, 0, 0, 0);
        list.getSelectedStyle().setPadding(0, 0, 0, 0);
        list.setPreferredW(leftPadding+preferredWidth+arrow.getPreferredW());
        dialog = new Dialog();
        dialog.setScrollableY(false);
        dialog.getContentPane().getSelectedStyle().setPadding(0, 0, leftPadding, 0);
        dialog.getContentPane().getUnselectedStyle().setPadding(0, 0, leftPadding, 0);
        dialog.addComponent(list);
        cListBox.addComponent(BorderLayout.WEST, libelle);
        cListBox.addComponent(BorderLayout.EAST, arrow);
        cListBox.setPreferredH(preferredHeight);
        getUnselectedStyle().setPadding(Component.LEFT, leftPadding);
        getSelectedStyle().setPadding(Component.LEFT, leftPadding);
        getUnselectedStyle().setBorder(Border.createLineBorder(1));
        getSelectedStyle().setBorder(Border.createLineBorder(1));
        addComponent(cListBox);
        setPreferredH(preferredHeight);
        getUnselectedStyle().setMargin(Component.TOP, topMargin);
        getSelectedStyle().setMargin(Component.TOP, topMargin);
        getUnselectedStyle().setMargin(Component.BOTTOM, bottomMargin);
        getSelectedStyle().setMargin(Component.BOTTOM, bottomMargin);
    }
    public void actionPerformed(ActionEvent ae)
    {
        if ( (ae.getSource() instanceof List) && ((List)ae.getSource()).equals(list) )
        {
            dialog.dispose();
            if (list.getSelectedItem() instanceof Content)
            {
                Content valeur = (Content)list.getSelectedItem();
                selectedData = valeur.getEnreg();
                libelle.setText(selectedData);
                repaint();
            }
        }
    }
    public void setSelectedIndex(int idx)
    {
        list.setSelectedIndex(idx);
        selectedData = String.valueOf(vData.elementAt(idx));
        libelle.setText(String.valueOf(vData.elementAt(idx)));
        repaint();
    }
    public String getSelectedData()
    {
        return selectedData;
    }
    public void pointerPressed(int x, int y)
    {
        int espaceVertRestant, top, bottom, left, right;
        espaceVertRestant = screenHeight - ( libelle.getAbsoluteY() + preferredHeight );
        if (espaceVertRestant > list.getPreferredH())
        {
            top = getAbsoluteY() + preferredHeight - 1 ;
            bottom = screenHeight - ( getAbsoluteY() + preferredHeight + list.getPreferredH() ) ;
        }
        else
        {
            top = screenHeight - ( list.getPreferredH() + preferredHeight + espaceVertRestant ) ;
            bottom = getAbsoluteY() ;
        }
        left = getAbsoluteX() ;
        right = screenWidth - ( getAbsoluteX() + getPreferredW() );
        dialog.show(top, bottom, left, right, false, true);
    }
}

这是 Form 的代码,我在其中添加了这个 ListBox 组件:

public class ModifierEcheanceForm extends Form implements ActionListener, DataChangedListener {

    private VirtualKeyboard vkNombre = new VirtualKeyboard();
    private String textFieldStatus, listBoxStatus;
    private Container cntnr = new Container();
    private Container c = new Container();
    private Container c1 = new Container();
    private Container c2 = new Container();
    private Container c3 = new Container();
    private Container c4 = new Container();
    private Container c5 = new Container();
    private Container c6 = new Container();
    private Container c7 = new Container();
    private Container c8 = new Container();
    private Container c9 = new Container();
    private Container c10 = new Container(new FlowLayout(Component.CENTER));
    private Container cz1 = new Container();
    private Container cz2 = new Container();
    private Container cz3 = new Container();
    private Container cz4 = new Container();
    private Container cz5 = new Container();
    private TextField t1=new TextField("zzz"),t2=new TextField("zzz"),t3=new TextField("zzz"),t4=new TextField("zzz"),t5=new TextField("zzz");
    private Button modifierBtn, reset;
    private BoxLayout bxl = new BoxLayout(BoxLayout.Y_AXIS);
    private BoxLayout bxltx = new BoxLayout(BoxLayout.X_AXIS);
    private boolean isMenuShown;
    private Command annulerCmd;
    private Command listeMenu, listeClientCmd, listeCreditCmd, ppalCmd;
    private Command ficheMenu, backCmd;
    private SmartPhoneBanking controler;
    private Form backForm, OldbackForm;
    private EcheanceDB echeancedb;
    private Vector listecheance = new Vector();
    private int idEcheance;
    private Label echedatelbl, montantlbl, eche_payelbl, eche_retardlbl, ecehe_nbretardlbl, eche_crdlbl, eche_rembourselbl, eche_interetlbl,flagPayelbl;
    private TextField echedatetxt, montanttxt, eche_payetxt, eche_retardtxt, ecehe_nbretardtxt, eche_crdtxt, eche_remboursetxt, eche_interettxt;
    private ListBox flagPayetxt;   // here is the ListBox
    private CreditDB creditdb = new CreditDB();
    private Vector listeCredit = new Vector();
    private String idClient, idCredit;
    public static int listEcheanceSelectedRow;

    public ModifierEcheanceForm(SmartPhoneBanking ctrl, int idEcheance, Form prevForm)
    {
        super("Modification échéance");
        vkNombre.setInputModeOrder(new String[]{VirtualKeyboard.NUMBERS_SYMBOLS_MODE});
        this.controler = ctrl;
        this.idEcheance = idEcheance;
        backForm = prevForm;
        OldbackForm = FicheCreditForm.backForm;

        echeancedb = new EcheanceDB();
        listecheance = echeancedb.echeanceParId(String.valueOf(idEcheance));

        idCredit = String.valueOf(listecheance.elementAt(5));
        listeCredit = creditdb.listCredit(Integer.parseInt(idCredit));
        idClient = String.valueOf(listeCredit.elementAt(12));

        c.setLayout(bxl);
        c1.setLayout(bxltx);
        c2.setLayout(bxltx);
        c3.setLayout(bxltx);
        c4.setLayout(bxltx);
        c5.setLayout(bxltx);
        c6.setLayout(bxltx);
        c7.setLayout(bxltx);
        c8.setLayout(bxltx);
        c9.setLayout(bxltx);

        echedatelbl = new Label("Date d'échéance");
        echedatelbl.setUIID("FicheLibelle");
        echedatetxt = new TextField();
        echedatetxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(echedatetxt, vkNombre);

        montantlbl = new Label("Montant(Ar)");
        montantlbl.setUIID("FicheLibelle");
        montanttxt = new TextField();
        montanttxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(montanttxt, vkNombre);

        eche_payelbl = new Label("Payé (Ar)");
        eche_payelbl.setUIID("FicheLibelle");
        eche_payetxt = new TextField();
        eche_payetxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(eche_payetxt, vkNombre);

        eche_retardlbl = new Label("Retard");
        eche_retardlbl.setUIID("FicheLibelle");
        eche_retardtxt = new TextField();
        eche_retardtxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(eche_retardtxt, vkNombre);

        ecehe_nbretardlbl = new Label("Nombre de retard");
        ecehe_nbretardlbl.setUIID("FicheLibelle");
        ecehe_nbretardtxt = new TextField();
        ecehe_nbretardtxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(ecehe_nbretardtxt, vkNombre);

        eche_crdlbl = new Label("Crédit (Ar)");
        eche_crdlbl.setUIID("FicheLibelle");
        eche_crdtxt = new TextField();
        eche_crdtxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(eche_crdtxt, vkNombre);

        eche_rembourselbl = new Label("Remboursé (Ar)");
        eche_rembourselbl.setUIID("FicheLibelle");
        eche_remboursetxt = new TextField();
        eche_remboursetxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(eche_remboursetxt, vkNombre);

        eche_interetlbl = new Label("Intérêt (Ar)");
        eche_interetlbl.setUIID("FicheLibelle");
        eche_interettxt = new TextField();
        eche_interettxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(eche_interettxt, vkNombre);

        flagPayelbl = new Label("Payé");
        flagPayelbl.setUIID("FicheLibelle");
        flagPayetxt = new ListBox(new String[]{"oui","non","aaaaaa","bbbb"},echedatetxt.getPreferredH(),getPreferredW(),getPreferredH(),eche_interettxt.getSelectedStyle().getMargin(Component.TOP),eche_interettxt.getSelectedStyle().getMargin(Component.BOTTOM));

        c10.getStyle().setPadding(Component.LEFT, 0);
        c10.getStyle().setPadding(Component.RIGHT, 0);

        reset = new Button("Rétablir les données");
        reset.addActionListener(this);
        reset.getUnselectedStyle().setMargin(0, 0, 0, 0);
        reset.getSelectedStyle().setMargin(0, 0, 0, 0);
        reset.setAlignment(Label.CENTER);
        reset.setUIID("btnDetailCreditFieldset");
        c10.addComponent(reset);

        modifierBtn = new Button("Valider");
        modifierBtn.addActionListener(this);
        modifierBtn.getUnselectedStyle().setMargin(0, 0, 0, 0);
        modifierBtn.getSelectedStyle().setMargin(0, 0, 0, 0);
        modifierBtn.setAlignment(Label.CENTER);
        modifierBtn.setUIID("btnDetailCreditFieldset");

        c1.addComponent(echedatelbl);
        c1.addComponent(echedatetxt);

        c2.addComponent(montantlbl);
        c2.addComponent(montanttxt);

        c3.addComponent(eche_payelbl);
        c3.addComponent(eche_payetxt);

        c4.addComponent(eche_retardlbl);
        c4.addComponent(eche_retardtxt);

        c5.addComponent(ecehe_nbretardlbl);
        c5.addComponent(ecehe_nbretardtxt);

        c6.addComponent(eche_crdlbl);
        c6.addComponent(eche_crdtxt);

        c7.addComponent(eche_rembourselbl);
        c7.addComponent(eche_remboursetxt);

        c8.addComponent(eche_interetlbl);
        c8.addComponent(eche_interettxt);

        c9.addComponent(flagPayelbl);
        c9.addComponent(flagPayetxt);

        cz1.addComponent(t1);
        cz2.addComponent(t2);
        cz3.addComponent(t3);
        cz4.addComponent(t4);
        cz5.addComponent(t5);

        int[] labelW = new int[]{echedatelbl.getPreferredW(), montantlbl.getPreferredW(), eche_payelbl.getPreferredW(), eche_retardlbl.getPreferredW(), ecehe_nbretardlbl.getPreferredW(), eche_crdlbl.getPreferredW(), eche_rembourselbl.getPreferredW(), eche_interetlbl.getPreferredW(),flagPayelbl.getPreferredW()};
        int largeW = Comparator.max(labelW);
        echedatelbl.setPreferredW(largeW);
        montantlbl.setPreferredW(largeW);
        eche_payelbl.setPreferredW(largeW);
        eche_retardlbl.setPreferredW(largeW);
        ecehe_nbretardlbl.setPreferredW(largeW);
        eche_crdlbl.setPreferredW(largeW);
        eche_rembourselbl.setPreferredW(largeW);
        eche_interetlbl.setPreferredW(largeW);
        flagPayelbl.setPreferredW(largeW+2);

        c10.addComponent(modifierBtn);

        c.addComponent(c1);
        c.addComponent(c2);
        c.addComponent(c3);
        c.addComponent(c4);
        c.addComponent(c5);
        c.addComponent(c6);
        c.addComponent(c7);
        c.addComponent(c8);
        c.addComponent(cz1);
        c.addComponent(cz2);
        c.addComponent(cz3);
        c.addComponent(cz4);
        c.addComponent(cz5);
        c.addComponent(c9);
        c.addComponent(c10);

        cntnr.addComponent(c);
        this.setScrollableY(true);
        this.addComponent(cntnr);

        echedatetxt.setText(listecheance.elementAt(0).toString());
        montanttxt.setText(listecheance.elementAt(1).toString());
        eche_payetxt.setText(listecheance.elementAt(6).toString());
        eche_retardtxt.setText(listecheance.elementAt(7).toString());
        ecehe_nbretardtxt.setText(listecheance.elementAt(8).toString());
        eche_crdtxt.setText(listecheance.elementAt(9).toString());
        eche_remboursetxt.setText(listecheance.elementAt(10).toString());
        eche_interettxt.setText(listecheance.elementAt(11).toString());
        textFieldStatus = "NORMAL";
        if (String.valueOf(listecheance.elementAt(2)).toLowerCase().startsWith("o"))
            flagPayetxt.setSelectedIndex(0);
        else if (String.valueOf(listecheance.elementAt(2)).toLowerCase().startsWith("n"))
            flagPayetxt.setSelectedIndex(1);

        listeMenu      = new Command("Liste");
        listeClientCmd = new Command("Clients");
        listeCreditCmd = new Command("Crédits");
        ppalCmd        = new Command("Menu principal");
        ficheMenu      = new Command("Fiche");
        backCmd        = new Command("Retour");
        annulerCmd     = new Command("Annuler");
        isMenuShown    = false;
        this.addCommand(listeMenu);
        this.addCommand(ficheMenu);
        this.addCommandListener(this);
    } // end of constructor
    ...
}

您会看到,我已经考虑了下面是否有空格的两种情况ListBox 类的 pointerPressed 方法中的 ListBox

当我没有在调用 Form 的代码中为容器 cz1 到 cz5 编写 addComponent 时,Dialog 会在下面很好地显示ListBox 组件。

那么,当底部没有更多空间时,为什么 Dialog 不显示呢?

I want to display a Dialog when I click on a userdefined component that I have created : I named its class name to ListBox. I want to simulate a LWUIT ComboBox with my user defined component which will accepts the blank area ; because LWUIT ComboBox doesn't accept the blank area.

The problem is that when my ListBox is at a coordinate such that there is no more space below it to display the Dialog then the Dialog is not shown ; but if there are more space below then the Dialog is shown.

Here is the captured image when the Dialog is not shown :

enter image description here

In the captured image the user defined ListBox is the component just above the two Buttons at the bottom of the phone screen.

And here are the codes :

public class ListBox extends Container implements ActionListener
{
    private Container cListBox = new Container(new BorderLayout());
    private Label[] tLabel;
    private int[] tLabelW;
    private int largestLabelW;
    private Label libelle = new Label();
    private Label arrow = new Label((MenuPrincipalForm.r).getImage("listboxarrow"));
    private int preferredWidth, preferredHeight, screenWidth, screenHeight;
    private Vector vData = new Vector();
    private final int leftPadding = 3;
    private CListCellListBox listRenderer;
    private List list;
    private Dialog dialog;
    private String selectedData;

    public ListBox(String[] lData, int prefHeight, int formWidth, int formHeight, int topMargin, int bottomMargin)
    {
        super(new FlowLayout(Component.CENTER));
        setFocusable(true);
        screenWidth = formWidth;
        screenHeight = formHeight;
        tLabel = new Label[lData.length + 1];
        tLabelW = new int[lData.length + 1];
        for (int i = 0 ; i < lData.length + 1 ; i++)
        {
            if (i < lData.length)
            {
                vData.addElement(new String(lData[i]));
                tLabel[i] = new Label(lData[i]);
                tLabelW[i] = tLabel[i].getPreferredW();
            }
            else
            {
                vData.addElement(new String(""));
                tLabel[i] = new Label("");
                tLabelW[i] = 0;
            }
        }
        largestLabelW = Comparator.max(tLabelW);
        preferredWidth = leftPadding + largestLabelW + arrow.getPreferredW();
        preferredHeight = prefHeight - 2 ;
        selectedData = String.valueOf(vData.lastElement());
        libelle.setText(String.valueOf(vData.lastElement()));
        libelle.setTextPosition(Label.LEFT);
        libelle.setPreferredW(preferredWidth);
        libelle.setPreferredH(preferredHeight);
        arrow.setAlignment(Label.CENTER);
        arrow.setPreferredH(preferredHeight);
        listRenderer = new CListCellListBox(false);
        list = (new CList(vData, false)).createList(listRenderer, this);
        list.setItemGap(0);
        list.setSelectedIndex(vData.indexOf(vData.lastElement()));
        list.getUnselectedStyle().setPadding(0, 0, 0, 0);
        list.getSelectedStyle().setPadding(0, 0, 0, 0);
        list.setPreferredW(leftPadding+preferredWidth+arrow.getPreferredW());
        dialog = new Dialog();
        dialog.setScrollableY(false);
        dialog.getContentPane().getSelectedStyle().setPadding(0, 0, leftPadding, 0);
        dialog.getContentPane().getUnselectedStyle().setPadding(0, 0, leftPadding, 0);
        dialog.addComponent(list);
        cListBox.addComponent(BorderLayout.WEST, libelle);
        cListBox.addComponent(BorderLayout.EAST, arrow);
        cListBox.setPreferredH(preferredHeight);
        getUnselectedStyle().setPadding(Component.LEFT, leftPadding);
        getSelectedStyle().setPadding(Component.LEFT, leftPadding);
        getUnselectedStyle().setBorder(Border.createLineBorder(1));
        getSelectedStyle().setBorder(Border.createLineBorder(1));
        addComponent(cListBox);
        setPreferredH(preferredHeight);
        getUnselectedStyle().setMargin(Component.TOP, topMargin);
        getSelectedStyle().setMargin(Component.TOP, topMargin);
        getUnselectedStyle().setMargin(Component.BOTTOM, bottomMargin);
        getSelectedStyle().setMargin(Component.BOTTOM, bottomMargin);
    }
    public void actionPerformed(ActionEvent ae)
    {
        if ( (ae.getSource() instanceof List) && ((List)ae.getSource()).equals(list) )
        {
            dialog.dispose();
            if (list.getSelectedItem() instanceof Content)
            {
                Content valeur = (Content)list.getSelectedItem();
                selectedData = valeur.getEnreg();
                libelle.setText(selectedData);
                repaint();
            }
        }
    }
    public void setSelectedIndex(int idx)
    {
        list.setSelectedIndex(idx);
        selectedData = String.valueOf(vData.elementAt(idx));
        libelle.setText(String.valueOf(vData.elementAt(idx)));
        repaint();
    }
    public String getSelectedData()
    {
        return selectedData;
    }
    public void pointerPressed(int x, int y)
    {
        int espaceVertRestant, top, bottom, left, right;
        espaceVertRestant = screenHeight - ( libelle.getAbsoluteY() + preferredHeight );
        if (espaceVertRestant > list.getPreferredH())
        {
            top = getAbsoluteY() + preferredHeight - 1 ;
            bottom = screenHeight - ( getAbsoluteY() + preferredHeight + list.getPreferredH() ) ;
        }
        else
        {
            top = screenHeight - ( list.getPreferredH() + preferredHeight + espaceVertRestant ) ;
            bottom = getAbsoluteY() ;
        }
        left = getAbsoluteX() ;
        right = screenWidth - ( getAbsoluteX() + getPreferredW() );
        dialog.show(top, bottom, left, right, false, true);
    }
}

Here is the code of the Form where I add this ListBox component :

public class ModifierEcheanceForm extends Form implements ActionListener, DataChangedListener {

    private VirtualKeyboard vkNombre = new VirtualKeyboard();
    private String textFieldStatus, listBoxStatus;
    private Container cntnr = new Container();
    private Container c = new Container();
    private Container c1 = new Container();
    private Container c2 = new Container();
    private Container c3 = new Container();
    private Container c4 = new Container();
    private Container c5 = new Container();
    private Container c6 = new Container();
    private Container c7 = new Container();
    private Container c8 = new Container();
    private Container c9 = new Container();
    private Container c10 = new Container(new FlowLayout(Component.CENTER));
    private Container cz1 = new Container();
    private Container cz2 = new Container();
    private Container cz3 = new Container();
    private Container cz4 = new Container();
    private Container cz5 = new Container();
    private TextField t1=new TextField("zzz"),t2=new TextField("zzz"),t3=new TextField("zzz"),t4=new TextField("zzz"),t5=new TextField("zzz");
    private Button modifierBtn, reset;
    private BoxLayout bxl = new BoxLayout(BoxLayout.Y_AXIS);
    private BoxLayout bxltx = new BoxLayout(BoxLayout.X_AXIS);
    private boolean isMenuShown;
    private Command annulerCmd;
    private Command listeMenu, listeClientCmd, listeCreditCmd, ppalCmd;
    private Command ficheMenu, backCmd;
    private SmartPhoneBanking controler;
    private Form backForm, OldbackForm;
    private EcheanceDB echeancedb;
    private Vector listecheance = new Vector();
    private int idEcheance;
    private Label echedatelbl, montantlbl, eche_payelbl, eche_retardlbl, ecehe_nbretardlbl, eche_crdlbl, eche_rembourselbl, eche_interetlbl,flagPayelbl;
    private TextField echedatetxt, montanttxt, eche_payetxt, eche_retardtxt, ecehe_nbretardtxt, eche_crdtxt, eche_remboursetxt, eche_interettxt;
    private ListBox flagPayetxt;   // here is the ListBox
    private CreditDB creditdb = new CreditDB();
    private Vector listeCredit = new Vector();
    private String idClient, idCredit;
    public static int listEcheanceSelectedRow;

    public ModifierEcheanceForm(SmartPhoneBanking ctrl, int idEcheance, Form prevForm)
    {
        super("Modification échéance");
        vkNombre.setInputModeOrder(new String[]{VirtualKeyboard.NUMBERS_SYMBOLS_MODE});
        this.controler = ctrl;
        this.idEcheance = idEcheance;
        backForm = prevForm;
        OldbackForm = FicheCreditForm.backForm;

        echeancedb = new EcheanceDB();
        listecheance = echeancedb.echeanceParId(String.valueOf(idEcheance));

        idCredit = String.valueOf(listecheance.elementAt(5));
        listeCredit = creditdb.listCredit(Integer.parseInt(idCredit));
        idClient = String.valueOf(listeCredit.elementAt(12));

        c.setLayout(bxl);
        c1.setLayout(bxltx);
        c2.setLayout(bxltx);
        c3.setLayout(bxltx);
        c4.setLayout(bxltx);
        c5.setLayout(bxltx);
        c6.setLayout(bxltx);
        c7.setLayout(bxltx);
        c8.setLayout(bxltx);
        c9.setLayout(bxltx);

        echedatelbl = new Label("Date d'échéance");
        echedatelbl.setUIID("FicheLibelle");
        echedatetxt = new TextField();
        echedatetxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(echedatetxt, vkNombre);

        montantlbl = new Label("Montant(Ar)");
        montantlbl.setUIID("FicheLibelle");
        montanttxt = new TextField();
        montanttxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(montanttxt, vkNombre);

        eche_payelbl = new Label("Payé (Ar)");
        eche_payelbl.setUIID("FicheLibelle");
        eche_payetxt = new TextField();
        eche_payetxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(eche_payetxt, vkNombre);

        eche_retardlbl = new Label("Retard");
        eche_retardlbl.setUIID("FicheLibelle");
        eche_retardtxt = new TextField();
        eche_retardtxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(eche_retardtxt, vkNombre);

        ecehe_nbretardlbl = new Label("Nombre de retard");
        ecehe_nbretardlbl.setUIID("FicheLibelle");
        ecehe_nbretardtxt = new TextField();
        ecehe_nbretardtxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(ecehe_nbretardtxt, vkNombre);

        eche_crdlbl = new Label("Crédit (Ar)");
        eche_crdlbl.setUIID("FicheLibelle");
        eche_crdtxt = new TextField();
        eche_crdtxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(eche_crdtxt, vkNombre);

        eche_rembourselbl = new Label("Remboursé (Ar)");
        eche_rembourselbl.setUIID("FicheLibelle");
        eche_remboursetxt = new TextField();
        eche_remboursetxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(eche_remboursetxt, vkNombre);

        eche_interetlbl = new Label("Intérêt (Ar)");
        eche_interetlbl.setUIID("FicheLibelle");
        eche_interettxt = new TextField();
        eche_interettxt.addDataChangeListener(this);
        VirtualKeyboard.bindVirtualKeyboard(eche_interettxt, vkNombre);

        flagPayelbl = new Label("Payé");
        flagPayelbl.setUIID("FicheLibelle");
        flagPayetxt = new ListBox(new String[]{"oui","non","aaaaaa","bbbb"},echedatetxt.getPreferredH(),getPreferredW(),getPreferredH(),eche_interettxt.getSelectedStyle().getMargin(Component.TOP),eche_interettxt.getSelectedStyle().getMargin(Component.BOTTOM));

        c10.getStyle().setPadding(Component.LEFT, 0);
        c10.getStyle().setPadding(Component.RIGHT, 0);

        reset = new Button("Rétablir les données");
        reset.addActionListener(this);
        reset.getUnselectedStyle().setMargin(0, 0, 0, 0);
        reset.getSelectedStyle().setMargin(0, 0, 0, 0);
        reset.setAlignment(Label.CENTER);
        reset.setUIID("btnDetailCreditFieldset");
        c10.addComponent(reset);

        modifierBtn = new Button("Valider");
        modifierBtn.addActionListener(this);
        modifierBtn.getUnselectedStyle().setMargin(0, 0, 0, 0);
        modifierBtn.getSelectedStyle().setMargin(0, 0, 0, 0);
        modifierBtn.setAlignment(Label.CENTER);
        modifierBtn.setUIID("btnDetailCreditFieldset");

        c1.addComponent(echedatelbl);
        c1.addComponent(echedatetxt);

        c2.addComponent(montantlbl);
        c2.addComponent(montanttxt);

        c3.addComponent(eche_payelbl);
        c3.addComponent(eche_payetxt);

        c4.addComponent(eche_retardlbl);
        c4.addComponent(eche_retardtxt);

        c5.addComponent(ecehe_nbretardlbl);
        c5.addComponent(ecehe_nbretardtxt);

        c6.addComponent(eche_crdlbl);
        c6.addComponent(eche_crdtxt);

        c7.addComponent(eche_rembourselbl);
        c7.addComponent(eche_remboursetxt);

        c8.addComponent(eche_interetlbl);
        c8.addComponent(eche_interettxt);

        c9.addComponent(flagPayelbl);
        c9.addComponent(flagPayetxt);

        cz1.addComponent(t1);
        cz2.addComponent(t2);
        cz3.addComponent(t3);
        cz4.addComponent(t4);
        cz5.addComponent(t5);

        int[] labelW = new int[]{echedatelbl.getPreferredW(), montantlbl.getPreferredW(), eche_payelbl.getPreferredW(), eche_retardlbl.getPreferredW(), ecehe_nbretardlbl.getPreferredW(), eche_crdlbl.getPreferredW(), eche_rembourselbl.getPreferredW(), eche_interetlbl.getPreferredW(),flagPayelbl.getPreferredW()};
        int largeW = Comparator.max(labelW);
        echedatelbl.setPreferredW(largeW);
        montantlbl.setPreferredW(largeW);
        eche_payelbl.setPreferredW(largeW);
        eche_retardlbl.setPreferredW(largeW);
        ecehe_nbretardlbl.setPreferredW(largeW);
        eche_crdlbl.setPreferredW(largeW);
        eche_rembourselbl.setPreferredW(largeW);
        eche_interetlbl.setPreferredW(largeW);
        flagPayelbl.setPreferredW(largeW+2);

        c10.addComponent(modifierBtn);

        c.addComponent(c1);
        c.addComponent(c2);
        c.addComponent(c3);
        c.addComponent(c4);
        c.addComponent(c5);
        c.addComponent(c6);
        c.addComponent(c7);
        c.addComponent(c8);
        c.addComponent(cz1);
        c.addComponent(cz2);
        c.addComponent(cz3);
        c.addComponent(cz4);
        c.addComponent(cz5);
        c.addComponent(c9);
        c.addComponent(c10);

        cntnr.addComponent(c);
        this.setScrollableY(true);
        this.addComponent(cntnr);

        echedatetxt.setText(listecheance.elementAt(0).toString());
        montanttxt.setText(listecheance.elementAt(1).toString());
        eche_payetxt.setText(listecheance.elementAt(6).toString());
        eche_retardtxt.setText(listecheance.elementAt(7).toString());
        ecehe_nbretardtxt.setText(listecheance.elementAt(8).toString());
        eche_crdtxt.setText(listecheance.elementAt(9).toString());
        eche_remboursetxt.setText(listecheance.elementAt(10).toString());
        eche_interettxt.setText(listecheance.elementAt(11).toString());
        textFieldStatus = "NORMAL";
        if (String.valueOf(listecheance.elementAt(2)).toLowerCase().startsWith("o"))
            flagPayetxt.setSelectedIndex(0);
        else if (String.valueOf(listecheance.elementAt(2)).toLowerCase().startsWith("n"))
            flagPayetxt.setSelectedIndex(1);

        listeMenu      = new Command("Liste");
        listeClientCmd = new Command("Clients");
        listeCreditCmd = new Command("Crédits");
        ppalCmd        = new Command("Menu principal");
        ficheMenu      = new Command("Fiche");
        backCmd        = new Command("Retour");
        annulerCmd     = new Command("Annuler");
        isMenuShown    = false;
        this.addCommand(listeMenu);
        this.addCommand(ficheMenu);
        this.addCommandListener(this);
    } // end of constructor
    ...
}

You see that I have considered the two cases if there is space or not below the ListBox in the pointerPressed method of the ListBox class.

When I don't write in the calling Form's code the addComponent for the containers cz1 through cz5 then the Dialog is shown very well below the ListBox component.

So why doesn't the Dialog show when there is no more space at the bottom ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情感失落者 2024-12-18 21:11:29

您调用对话框显示方法时,其大小不会为对话框留下任何空间。您需要检查高度 - 顶部 - 底部 > dialogPreferreHeight 并且同样适用于宽度。

请参阅组合框弹出代码,如果下面没有空间,我们有条件地向上弹出对话框。

You invoke the dialog show method with sizes that don't leave any space for the dialog. You need to check that height - top - bottom > dialogPreferreHeight and the same should apply for width.

See the combo box popup code where we conditionally popup the dialog upwards if there is no room bellow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文