Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6723883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:37:20+00:00 2026-05-26T09:37:20+00:00

There is a user defined component , derived from Container , inside my Form

  • 0

There is a user defined component , derived from Container, inside my Form. It has a pointerPressed method implemented in its class code. In the code of that method I show a Dialog containing a List , and in the class code of the derived Dialog ( in the constructor ) I set the setDisposeWhenPointerOutOfBounds method with the argument value to true.

The problem is that in run time when I click the user defined component ( ListBox ) in my Form then the Dialog is shown , of course , but immediately it closes ( disposes ) , although I don’t click outside the boundary of the Dialog !

So why does it have such a behavior ?

Codes :

public class ListBox extends Container
{
    private Form containerForm;
    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 int listW;
    private List list;
    private DialogListBox dialog;
    private String selectedData;

    public ListBox(Form containingForm, String[] lData, int prefHeight, int formWidth, int formHeight, int topMargin, int bottomMargin)
    {
        super(new FlowLayout(Component.CENTER));
        setFocusable(true);
        containerForm = containingForm;
        screenWidth = formWidth;
        screenHeight = formHeight;
        tLabel = new Label[lData.length + 1];
        tLabelW = new int[lData.length + 1];
        if (lData.length > 0)
        {
            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;
                }
            }
        }
        else
        {
            vData.addElement(new String(""));
            tLabel[0] = new Label("");
            tLabelW[0] = 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);

        dialog = new DialogListBox(leftPadding, this);
        list = dialog.getList();

        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 setSelectedIndex(int idx)
    {
        list.setSelectedIndex(idx);
        selectedData = String.valueOf(vData.elementAt(idx));
        libelle.setText(String.valueOf(vData.elementAt(idx)));
        repaint();
    }
    public void setSelectedData(String data)
    {
        selectedData = data;
        libelle.setText(selectedData);
        repaint();
    }
    public String getSelectedData()
    {
        return selectedData;
    }
    public int getLastIndex()
    {
        return vData.indexOf(vData.lastElement());
    }
    public Vector getListBoxDataSource()
    {
        return vData;
    }
    private void showListBoxDialog()
    {
        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() - 1 ;
        }
        left = getAbsoluteX() ;
        right = screenWidth - ( getAbsoluteX() + getPreferredW() );
        listW = screenWidth - left - right ;
        containerForm.setTintColor(containerForm.getSelectedStyle().getBgColor());
        dialog.setListW(listW);
        dialog.show(top, bottom, left, right, false, false);
    }
    public void keyPressed(int keyCode)
    {
        int gameAction = (Display.getInstance()).getGameAction(keyCode);
        if (gameAction == Display.GAME_FIRE)
            showListBoxDialog();
        else
            super.keyPressed(keyCode);
    }
    public void pointerPressed(int x, int y)
    {
        showListBoxDialog();
    }
}

public class DialogListBox extends Dialog implements ActionListener
{
    private Vector vData;
    private CListCellListBox listRenderer;
    private List list;
    private ListBox theListBox;
    public DialogListBox(int leftPadding, ListBox listBox)
    {
        super();
        setFocusable(true);
        setDisposeWhenPointerOutOfBounds(true);
        getContentPane().getSelectedStyle().setPadding(0, 0, 0, 0);
        getContentPane().getUnselectedStyle().setPadding(0, 0, 0, 0);
        getContentPane().getStyle().setPadding(0, 0, 0, 0);
        theListBox = listBox;
        listRenderer = new CListCellListBox(false);
        vData = listBox.getListBoxDataSource();
        list = (new CList(vData, false)).createList(listRenderer, this);
        list.setItemGap(0);
        list.setSelectedIndex(vData.indexOf(vData.lastElement()));
        list.getSelectedStyle().setPadding(0, 0, leftPadding, 0);
        list.getUnselectedStyle().setPadding(0, 0, leftPadding, 0);
        list.getUnselectedStyle().setBorder(Border.createLineBorder(1), false);
        list.getSelectedStyle().setBorder(Border.createLineBorder(1), false);
        list.setIsScrollVisible(false);
        addComponent(list);
    }
    protected void onShow()
    {
        list.requestFocus();
        repaint();
    }
    public void setListW(int prefW)
    {
        list.setPreferredW(prefW);
    }
    public List getList()
    {
        return list;
    }
    private void refreshListBox()
    {
        dispose();
        if (list.getSelectedItem() instanceof Content)
        {
            Content valeur = (Content)list.getSelectedItem();
            theListBox.setSelectedData(valeur.getEnreg());
        }
    }
    public void keyPressed(int keyCode)
    {
        int gameAction = (Display.getInstance()).getGameAction(keyCode);
        if (gameAction == Display.GAME_FIRE)
            refreshListBox();
        else
            super.keyPressed(keyCode);
    }
    public void actionPerformed(ActionEvent ae) {
        if ( (ae.getSource() instanceof List) && ((List)ae.getSource()).equals(list) )
            refreshListBox();
    }
}

public class CList {

    private Vector data = new Vector();
    private boolean showPhoto;
    private Content[] contents;

    public CList(Vector vData, boolean displayPhoto)
    {
        data = vData;
        showPhoto = displayPhoto;
        contents = new Content[vData.size()];
    }

    public List createList(CListCell renderer, ActionListener listener)
    {
        List theList;
        if (showPhoto)
        {
            for(int i = 0; i < data.size(); i++)
            {
                Image img = getFirstImage(Formatage.getColumnValueAt(String.valueOf(data.elementAt(i)), 0));
                contents[i] = new Content(img, String.valueOf(data.elementAt(i)));
            }
        }
        else
        {
            for(int i = 0; i < data.size(); i++)
            {
                contents[i] = new Content(String.valueOf(data.elementAt(i)));
            }
        }
        theList = new List(contents);
        theList.setListCellRenderer(renderer);
        theList.setFixedSelection(List.FIXED_NONE_CYCLIC);
        theList.addActionListener(listener);
        return theList;
    }
    // ... other methods 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:37:21+00:00Added an answer on May 26, 2026 at 9:37 am

    You should always use pointerReleased/keyReleased for navigation to different forms/dialogs.

    Otherwise the pointer/key released will be sent to the next form/dialog and trigger an action there.

    Pointer pressed is mostly used internally in LWUIT and for some special cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way I can query from within Vim information about user-defined vimscript
In a user defined wizard page, is there a way to capture change or
Are there known issues with storing user defined types within index organized tables in
Is there a way to declare a variable with a particular user-defined type in
In a large Application is there any way to distinguish user-defined classes with built-in
Is there a way to run the GCC preprocessor, but only for user-defined macros?
I have some logic, which defines and uses some user-defined types, like these: class
i have this MySQL statement from a search page, the user enters there postcode
In SQLITE there is a possibility to relatively easily create User-Defined Functions and Aggregates
I am trying to use Autoit with Ruby. There are some user defined functions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.