Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #4095

Re: ComboBox

From "tomaszewski.p" <tomaszewski.p@THRWHITE.remove-dii-this>
Subject Re: ComboBox
Message-ID <510c05f0-1cc3-498e-a8dc-e948e73f31a6@l33g2000pri.googlegroups.com> (permalink)
Newsgroups comp.lang.java.gui
References <1eee9ff3-e3ae-4e2e-9cd2-e95cd467dd77@b30g20
Date 2011-04-27 15:48 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
mamta81 napisa=B3(a):
> hi all ,
>              I have a comboBox .whenever i click on it the
> dropdownlist shows up but on clicking on any item in the list the
> clicked item gets selected and the list disappears.I want the list to
> remain so that i can scroll down through the lictby clicking on any
> alphabet.
> for example suppose i want to see all the items starting with letter
> C ,only the first item starting with C gets selected and the drop down
> disappears.i should be able to scroll through all the items starting
> with C in the dropdown of the combobox.
>
> Please help

Try this:

import java.awt.BorderLayout;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;

import javax.swing.plaf.basic.BasicComboBoxUI;
import javax.swing.plaf.basic.BasicComboPopup;
import javax.swing.plaf.basic.ComboPopup;


public class Test {

    static class ComboPanel extends JPanel {
        public ComboPanel() {
            final JComboBox combo =3D new JComboBox();
            combo.setUI(new ComboBoxUI());
            combo.addItem("One");
            combo.addItem("Two");
            combo.addItem("Three");
            setLayout(new BorderLayout());
            add(combo, BorderLayout.CENTER);
        }
    }

    static class ComboBoxUI extends BasicComboBoxUI {
        protected ComboPopup createPopup() {
            return new ComboBoxPopup(comboBox);
        }
    }

    static class ComboBoxPopup extends BasicComboPopup {

        public ComboBoxPopup(JComboBox combo) {
            super(combo);
        }

        protected MouseListener createListMouseListener() {
            return new MouseAdapter() {
                // TODO: add your implementation here
            };
        }
    }

    public static void main(String[] args) {
        final JFrame frame =3D new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new BorderLayout());
        frame.add(new ComboPanel(), BorderLayout.CENTER);
        frame.pack();
        frame.setVisible(true);
    }
}

Best regards,
Przemek

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | Next | Find similar | Unroll thread


Thread

Re: ComboBox "tomaszewski.p" <tomaszewski.p@THRWHITE.remove-dii-this> - 2011-04-27 15:48 +0000

csiph-web