Eliminate Items in JComboBox???

Hi @all,
does anybody know how I can eliminate the items of a JComboBox?
I am reading the items of the JComboBox out of a file and then I add them. When I am adding one item to the file and read the items again, I habe all the items two times in my JComboBox. The new one of course not.
How can I delete them first.
Chao
Juergen

Thank you.
Juergen

Similar Messages

  • Hi...it keeps saying my startup disk is almost full. Where do I go to eliminate items in the start up disk?   Thanks

    It keeps saying that my start up disk is almost full. Where do I go to eliminate items in the start up disk??  Thx

    Give this page a read for a better understanding of the Storage tab
    http://pondini.org/OSX/LionStorage.html

  • Create a PopupMenu when right click onto an item of JComboBox

    How do I make so that, a popupmenu appear only when I right click onto a item of JComboBox. What I have right now is showing a PopupMenu whenever I right click on the frame.
    I got another question to ask if you guys dont mind. How do I set the ComboBox to scroll horizontally. Right now I set the preferredSize of the ComboBox so if the item's names are too long, it will be cut off. Can I set it so that I can scroll horizontally to see the rest of the item's name?

    My English is very poor, so it's hard to explain...
    3.
    // This is just an example code and has not been tested.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.plaf.basic.*;
    public class ComboRightClickTest{
      public JComponent makeUI(final JFrame frame) {
        frame.setGlassPane(new LockingGlassPane());
        String[] items = {"test1", "test2", "test3"};
        JComboBox combo = new JComboBox(items);
        combo.setUI(new BasicComboBoxUI() {
          protected ComboPopup createPopup() {
            return new BasicComboPopup( comboBox ) {
              protected JList createList() {
                return new JList( comboBox.getModel() ) {
                  public void processMouseEvent(MouseEvent e)  {
                    if(e.isPopupTrigger()) {
                      String s = getSelectedValue().toString();
                      frame.getGlassPane().setVisible(true);
                      final JPopupMenu m = new JPopupMenu();
                      final JMenuItem i = new JMenuItem(
                          new AbstractAction("del:"+s) {
                        public void actionPerformed(ActionEvent ae) {
                          comboBox.removeItemAt(getSelectedIndex());
                          frame.getGlassPane().setVisible(false);
                          m.setVisible(false);
                      i.addMouseListener(new MouseAdapter() {
                        public void mouseEntered(MouseEvent me) {
                          i.setBackground(getSelectionBackground());
                        public void mouseExited(MouseEvent me) {
                          i.setBackground(getBackground());
                      m.add(i);
                      Point p = e.getPoint();
                      SwingUtilities.convertPointToScreen(p, this);
                      m.show(null, p.x, p.y);
                      return;
                    super.processMouseEvent(e);
        JPanel p = new JPanel(new BorderLayout());
        p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
        p.add(combo, BorderLayout.NORTH);
        p.setPreferredSize(new Dimension(320, 100));
        return p;
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          public void run() { createAndShowGUI(); }
      public static void createAndShowGUI() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        f.getContentPane().add(new ComboRightClickTest().makeUI(f));
        f.setResizable(false); //XXX
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    class LockingGlassPane extends JComponent {
      public LockingGlassPane() {
        setOpaque(false);
      @Override public void setVisible(boolean isVisible) {
        boolean oldVisible = isVisible();
        super.setVisible(isVisible);
        JRootPane rootPane = SwingUtilities.getRootPane(this);
        if(rootPane!=null && isVisible()!=oldVisible) {
          rootPane.getLayeredPane().setVisible(!isVisible);
      @Override public void paintComponent(Graphics g) {
        JRootPane rootPane = SwingUtilities.getRootPane(this);
        if(rootPane!=null) {
          http://weblogs.java.net/blog/alexfromsun/archive/2008/01/
          rootPane.getLayeredPane().print(g);
        super.paintComponent(g);
    }

  • How to select multiple items in JComboBox

    Is it possible to select multiple items in a JComboBox
    if yes, then how to do?
    If no , then is there any other way to acheieve this ?

    Hi
    ComboBoxModel extends ListModel and not ListSelectionModel, so i think JComboBox does not provide multiple selection. But u can try customizing ur combo box.. may be its possible.. not very sure
    Shailesh

  • How to detect if an item of JComboBox is highlighted?

    Good day.
    How to detect if the selected item of a JComboBox is highlighted or not?
    Thanks for your response.

    the above code can only detect a highlight if an item is selected from the combo box.
    But when the focus is transfered to other Combo box it can no longer keep track if the item was highlighted or not.
    for example:
    combo box 1 combo box 2
    item item2
    Highlight should be detected wheneverr the focus is transfered from combo box 1 to combo box 2 or vice versa.
    case:
    Combo box 1 item is highlighted before transfering the focus to combo box 2 item. by the time the focus is transfered , highlight in combox 1 item should be detected.
    The main problem here is how to detect if the previously focused item is highlighted or not.
    thank you for your time.

  • Load items in JComboBox

    Hi all,
    May i know how to load the files from a folder into a JComboBox.
    How can i refresh the items everytime the comboBox is clicked?

    When you instanciate your combo model, create an instance of File with the path to the folder as the constructor's parameter.
    With this File instance, use the method listFiles() to get the list of files contained in the folder. Populate your model with the items.
    For your second question, all of the above can be put in a seperate method, then you only have to call it when the combo is clicked.
    Of course, after your model has been modified, don't forget to fire an appropriate event to the combo.

  • Changing background of selected item in JComboBox when Uneditable

    I need to change the color of the items in a JComboBox list based on the values that change at runtime. I have accomplished this by creating and using a class extended from DefaultListCellRenderer.
    The combobox is enabled and uneditable. The problem is that in 1.5 the behavior changed and now the selected item gets a white background that is set by the UI or DefaultJComboBox. I can no longer set the background for the selected item.
    I have tried using the ComBox Editor. Also, the universal option of UIManager.put("ComboBox.background", Color.xxx) will not work since I have multiple boxes with different backgrounds.
    Does anyone no a work around?

    Unless I misread your problem you may find that your use of DefaultListCellRenderer is incorrect. The following snippet of code (using Java 1.5.0_07) will make the combo box red. The unselected items in the dropdown will be magenta and the selected item orange.
    combo.setBackground(Color.red);
    combo.setRenderer(new DefaultListCellRenderer()     {
         public Component getListCellRendererComponent(JList list,
                    Object value,
                    int index,
                    boolean isSelected,
                    boolean cellHasFocus)
                   Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                   if(isSelected)
                        c.setBackground(Color.ORANGE);
                   else
                        c.setBackground(Color.MAGENTA);
                   return c;
         });

  • Read item from Jcombobox to jtextarea

    Hi Guys,
    Pls how do i read a selected item from a jtextbox into a jtextarea.
    i've tried using the getText & the getSelecteditem methods but i keep getting errors.
    ie.
    display.append(name.getText());
    display.append(name.getSelecteditem());
    name is the jcombobox

    display.append(name.getText());
    there is no getText() method for JComboBox, unless your cb is editable,
    then you need to get the editor component, not the comboBox, and use getText()
    display.append(name.getSelecteditem());
    textArea.append(..) takes a string as its argument
    name.getSelecteditem() returns an object
    try
    display.append((String)name.getSelecteditem());

  • How to change the visible item of JCombobox

    hi,
    i have created a JCombobox having items A, B, C, D and E. The item that is visible on the combobox (without performing any mouse action over it) is A. i have a button "Change to Default" in the same frame. If I click on this button B should become the visible content of ComboBox in place of A. Could anyone suggest me how to do it.
    Thank you very much...

    Well, you could start by reading the documentation for JComboBox: http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JComboBox.html
    There you will find setSelectedIndex and setSelectedItem. Either of those will do it for you.

  • How to eliminate "items contains age-restricted material" message

    Hello folks,
    I am an adult with no children.  Is there a way to eliminate the popup message about "items contains age-restricted material" when updating or buying an app on iTunes?  I do not desire to be annoyed by this message.
    Thank you,
    Loren

    This is surely legal protection for Apple &al
    I'm sure Apple could work another way around this, but it would take a lot of people writing to them,
    sending feedback: http://www.apple.com/feedback/itunesapp.html
    Something like this:
    "Is there not another way around avoiding the constant notice pop-up message of 'age-restricted material' when downloading and updating certain apps?
    A declaration that I am the sole users of the PC and iTunes and have no children, for example.
    Or simply having iTunes remember my choice of accepting these apps. (and stating "this notice will appear once - you can reset this in settings if you no longer accept the term"  or something simple like that.)

  • Adding items in JComboBox - Help

    Hy, I have a JComboBox() and a JTextField().
    when I input a name in the JTextField and clicks on the "Ok" button
    the name is added in the JComboBox().
    What I want is when I click on the "Ok" button, a check is made to see
    whether the name input in the JTextField already exist in the JComboBox().
    If is exist a message is displayed else it is added.
    How to perform the check.
    PLease send me code for doing this.
    thanks

    Hi.
    The JComboBox uses a model to get its hands on the elements to be displayed. Thus you must search the model to see if the string is already contained.
    Use something like this:
        public boolean contains(JComboBox comboBox, String s) {
            int elementCount = comboBox.getModel().getSize();
            for (int i = 0; i < elementCount; i ++) {
                String t = (String)comboBox.getModel().getElementAt(i);
                if (t.equals(s))
                    return true;
            return false;
        }Hope this helps,
    Michael

  • Retrieving item from JCombobox

    hi,
    I am populating a jcombobox from a database table.
    the combobox accepts and displays "last name, First name ID #"
    I want to separate out and retrieve only the ID # so that I can run a report based on the selected ID #.
    The following code will pull the entire string but I need to 'grab' the ID # separately.
    jcmbPharmacist.getSelectedItem().toString();
    Can someone assist me?
    Thank you

    In the future, you should post Swing related questions in the Swing forum.
    For an example of storing an Object in a combo box check out this posting:
    http://forum.java.sun.com/thread.jspa?threadID=608684&messageID=3327290

  • How do convert selected item in JComboBox to String?

    I'm trying to get an option from a JComboBox to print in a JTextArea upon click.
    I've tried many ways, including converting to String, String array, and using textArea.append which doesn't seem to work either. .
    can anyone help?

    toString and actionlistener, bah. figured it out, sorry to trouble you :)

  • How to deauthorize or eliminate items

    A while ago I bought  an e-reader that could no be authorize, so the shop changed it and I could authorize it. Unfortunately the reader had other problems and I gave it back to get another one... unfortunately with the same problem. Finally I bought a new one somewhere else. That means the there are 2 readers good for nothing that account for the 6 devices I can authorize.
    If one day I need to authorize another computer or reader... where do I have to ask for that????
    I looked around but could not find the right place.

    We had a similar issue with configuring IIS on two servers.Unfortunately had to start from scratch.

  • Associate Action with jcombobox item

    Is it possible to associate a particular Action with a jcombobox item (for example using setAction()). When the user selects a particular item of jcombobox, the Action must be triggered.
    regards,
    Nirvan.

    Hi,
    You can associate a particular action with a JComboBox. As per my understanding u can add one action perfrom action to combobox or itemStateChanged action
    if u add action perform action, u need to add the following method to ur logic.
    JComboBox combobox=new JComboBox();
        combobox.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
             JComboBox combo = (JComboBox)evt.getSource();
                if(combo.getSelectedItem().equals("LOCATION")) {
                A a = new A();
                a.show();
            } else if(combo.getSelectedItem().equals("HOUSE")) {
                B b= new B();
                b.show();
            });if action is ItemStateChanged then add the following method.
    combobox.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt) {
                    and write your logic here which one needs to be triggered when this action performed.
            });Hope this will help to you....
    Thanks & Regards,
    Maadhav..

Maybe you are looking for

  • How can I add page numbers using Adobe Reader?

    I am trying to add page numbers to my document only using Adobe Reader.  Is that possible?  Or do I need to use Adobe Acrobat?

  • Check this out.

    After much fine tuneing and a few small problems solved by updating my bios. I managed this OC. I have to say I love this system. Thanks Tire Smoke and everyone who helped me.

  • Recording my cell phone conversations.

    How can I record a cell phone conversation on my Nokia windows phone? Is there an app for this? Or something I'm missing on the phone?

  • Choosing the account email alarms are sent from

    I have Mail.app configured with three e-mail accounts; two for home and one for work. When an alarm is sent, iCal sometimes tries to send it from my work account; but, if I'm not logged into the VPN, it will fail sending. Is there any way to specify

  • When creating system copy of PRD sistem to QAS system how to create transpo

    when creating system copy of PRD sistem to QAS system how to create transport request queue on QAS with: everything transported to QAS previously but not transported to PRD. We have an approval procedure with delete form queue on QAS after import. Ba