Actionlistener for JCombobox with JCheckbox

Hi!
I have written a JComboBox item which holds a checkbox :
public class CheckComboItem extends JCheckBox{
    private static final long serialVersionUID = 1677961185556377734L;
    public Integer id = 0;
    public CheckComboItem(Integer id, String text, Boolean state) {
        super(text, state);
        this.id = id;
}This works fine; However i have problems with my action listener, which should change the checkbox' selection state.
Unfortunately this only works sometimes (randomly) :-(
public class CheckComboListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
        JComboBox cb = (JComboBox) e.getSource();
        CheckComboItem store = (CheckComboItem) cb.getSelectedItem();
        store.setSelected((!store.isSelected()));
}Can you please tell me what i am doing wrong/ how this needs to be improved ?
Thank you very much!

You managed to find the Swing forum the last time you posted a Swing question.
Why didn't you search the Swing forum this time before you posted a question?
Maybe a JCheckBoxMenuItem will work better.
If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.

Similar Messages

  • ActionListener for JComboBox

    If I add an ActionListener to JComboBox or ComboBoxEditor I can get notified when user types some text into the combo-box and presses enter.
    If I need to get notifications after user types each letter. What should I do ?
    I'm stuck with this problem for a long time (I'm a beginner) - any help would be greatly appreciated. Thanks a lot,
    --Sergei 

    This would be my solution. There may be more but, this is the mest i can do;)
    So adding KeyListener.
    Let "cb" be your JComboBox object name, what you have to do is:
    cb.setEditable(true);
    ComboBoxEditor ce = cb.getEditor();
    ce.getEditorComponent().addKeyListener(this);
    here is the entire example. This progtram will count your keyevents
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Example extends Frame implements KeyListener
         private JComboBox cb = new JComboBox();
         private JLabel lab = new JLabel(" ");
         int numb = 0;
         public Example()
              cb.setEditable(true);
              ComboBoxEditor ce = cb.getEditor();
              ce.getEditorComponent().addKeyListener(this);
              setLayout(new FlowLayout());
              add(cb);
              add(lab);
              setSize(200,200);
              show();
         public static void main(String args[])
              new Example();          
         public void keyPressed(KeyEvent e)
         public void keyReleased(KeyEvent e)
                   numb ++;
                   lab.setText(Integer.toString(numb));
         public void keyTyped(KeyEvent e)

  • Actionlistener - for multiple buttons with similar functionality

    Hi, all:
    I'm working on a calculator program and want to know how to go about making a generic ActionListener for all the functions (i.e. +,-,*,/) so that I don't have to write separate inner classes for each function (i.e. + button, - button, etc.).
    I think this generic class should be created within a method that takes parameters. The parameters are then used within the inner class.
    What I need to know specifically is whether it's possible to pass a string operator symbol (e.g. "+" or "-") as a parameter in the following context:
    class buttonListener implements ActionListener
    public void actionPerformed(ActionEvent e)
    intField1Val + intFieldVal2;
    in this case, the "+" would be the parameter that would change depending on the values provided to the method.
    Can this be done??
    I'd also appreciate any other feedback you can give m,e on this problem (i.e. how to set up the method...basic structure??)
    Thanks!!

    Hi there,
    One way to do this is as follows:
    Button plus = new Button("+");
    Button minus = new Button("-");
    public void actionPerformed(ActionEvent e) {
    String componentHit = e.getActionCommand();
    if (componentHit == "+") {
    doAddMeth(); // implemented elsewhere
    else
    if (componentHit == "-") {
    doSubMeth(); // implemented elsewhere
    ~Bill

  • Problem with JCheckBox in a JTable

    Hello,
    I have a JTable with JCheckBox as Editor for boolean values.
    I added a ListSelectionListener on that JTable.
    My problem is :
    when I click on a cell which have a JCheckBoxEditor, there is only one event generated : the one which unselect the row previously selected.
    So i can't answer the selection.
    what could have append ?
    thanks a lot.
    fleur.

    hi,
    I have no custom editor for this table.
    here is my code :
    public VDEComposant(Locale langue,InterfaceModeleur listener,Composant composant,int largeur) {
    super(langue,listener,largeur);
    this.setLayout(new BorderLayout());
    _modele=listener.getModele();
    _composantCourant=composant;
    this.addComposantsListener((ComposantsListener)listener.getGestionnaire());
    construitBarreOutils();
    setNbLigne1(this.listeComposant(composant).size());
    int m=0;
    if (composant==Composant.COMPOSANT){
    _donCompPereApTM=this.creeModeleDonnee1(composant);
    _donCompPereApTM.addTableModelListener(this);
    setTableau1(new JTable(_donCompPereApTM));
    m=1;
    else{
    if (composant.getPere()==Composant.COMPOSANT){
    _donCompApTM=creeModeleDonnee1(composant);
    _donCompApTM.addTableModelListener(this);
    setTableau1(new JTable(_donCompApTM));
    else {
    _donCompUtTM=creeModeleDonnee1(composant);
    _donCompUtTM.addTableModelListener(this);
    setTableau1(new JTable(_donCompUtTM));
    getTableau1().addMouseListener(((OngletDonnees)((OngletDonnees)getIHM().getOngletDonnees())).getOngletComposants());
    MultipleComboBoxCellEditor editor = new MultipleComboBoxCellEditor(new JComboBox());
    getTableau1().getColumnModel().getColumn(4+m).setCellEditor(editor) ;
    getTableau1().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    getTableau1().getSelectionModel().addListSelectionListener(this);
    Dimension d1 = new Dimension(_largeur, getNbLigne1()*16);
    JScrollPane sc1 = new JScrollPane(getTableau1());
    sc1.setViewportView(getTableau1());
    if((composant.getPere()!=null)&&(composant.getPere()!=Composant.COMPOSANT)){
    this.add(_outils,BorderLayout.NORTH);
    String s="";
    if((composant.getPere()==null)||(composant.getPere()==Composant.COMPOSANT)){
    String sc="";
    if(composant==Composant.COMPOSANT_IMAGE){
    sc=" "+_ressources.getString("images");
    if(composant==Composant.COMPOSANT_LINEAIRE){
    sc=" "+_ressources.getString("lineaires");
    if(composant==Composant.COMPOSANT_METAD){
    sc=" "+_ressources.getString("lotdonnees");
    if(composant==Composant.COMPOSANT_NGS){
    sc=" "+_ressources.getString("nongraphiques");
    if(composant==Composant.COMPOSANT_SURFACIQUE){
    sc=" "+_ressources.getString("surfaciques");
    if(composant==Composant.COMPOSANT_SYMBOLIQUE){
    sc=" "+_ressources.getString("symboliques");
    s=_ressources.getString("liste_composant")+sc;
    else{
    s=_ressources.getString("description_composant");
    JLabel lab = new JLabel(s,JLabel.CENTER);
    JPanel inter = new JPanel(new GridLayout(1,1));
    inter.add(lab);
    inter.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(),BorderFactory.createEtchedBorder()));
    Box boite1 = Box.createVerticalBox();
    boite1.add(inter);
    boite1.add(sc1);
    _inter.add(boite1);
    //ajout du deuxieme tableau
    _donAttCompTM=this.creeModeleDonnee2(composant);
    _donAttCompTM.addTableModelListener(this);
    setTableau2(new JTable(_donAttCompTM));
    getTableau2().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    getTableau2().getSelectionModel().addListSelectionListener(this);
    getTableau2().addMouseListener(((OngletDonnees)((OngletDonnees)getIHM().getOngletDonnees())).getOngletComposants());
    //ComboBox pour saisir le type de l'attribut
    _typeA = new JComboBox();
    _typeA.addItem(TypeEtendu.DATE.getNom());
    _typeA.addItem(TypeEtendu.DOMAINE.getNom());
    _typeA.addItem(TypePrimitif.ENTIER.getNom());
    _typeA.addItem(TypePrimitif.LOGIQUE.getNom());
    _typeA.addItem(TypePrimitif.REEL.getNom());
    _typeA.addItem(TypePrimitif.TEXTE.getNom());
    (getTableau2().getColumnModel().getColumn(3)).setCellEditor(new DefaultCellEditor(_typeA));;
    //renderer pour la colonne des nom qui indique en gras l'attribut identifiant
    getTableau2().getColumnModel().getColumn(1).setCellRenderer(new AttributTableCellRenderer(_composantCourant));
    Dimension d2 = new Dimension(_largeur ,(getNbLigne2()*16));
    JScrollPane sc2 = new JScrollPane(getTableau2());
    sc2.setViewportView(getTableau2());
    _inter.createVerticalStrut(16);
    inter = new JPanel(new GridLayout(1,1));
    lab = new JLabel(_ressources.getString("attributs"),JLabel.CENTER);
    inter.add(lab);
    inter.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(),BorderFactory.createEtchedBorder()));
    Box boite2=Box.createVerticalBox();
    boite2.add(inter);
    boite2.add(sc2);
    _inter.add(boite2);
    if((composant.getPere()!=null)&&(composant.getPere()!=Composant.COMPOSANT)){
    this.add(_inter,BorderLayout.CENTER);
    else{
    this.add(_inter,BorderLayout.NORTH);
    public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting()) return;
    ListSelectionModel lsm =(ListSelectionModel)e.getSource();
    if (lsm.isSelectionEmpty()) {
    else {
    int ligneSel = lsm.getMinSelectionIndex();
    if(e.getSource()==getTableau2().getSelectionModel()){
    String alias = (String) _donAttCompTM.getValueAt(ligneSel,1);
    attribut = composantCourant.getAttribut(alias);
    else if(e.getSource()==getTableau1().getSelectionModel()){
    VectorTableModel vtm = null;
    int i = 0;
    if(_donCompApTM != null){
    vtm = _donCompApTM;
    if(_donCompPereApTM != null){
    vtm = _donCompPereApTM;
    i =1;
    if(vtm != null){
    String alias = (String) vtm.getValueAt(ligneSel,i);
    composantSelectionne= modele.getComposant(alias);
    else{
    composantSelectionne=composantCourant;
    I hope it make sens,
    thanks.

  • JComboBox with Custon Renderer Problem

    Hi, I am using a JComboBox with a custom ListCellRenderer that changes the colors of the strings on the list depending on some circunstances. The problem is that the changes only work on the list, but when one item is finally selected, and the list is no longer visible, the selected item has the default format (no colors)
    Thanks in advance

    I am not exactly sure what you mean, but here is something I wrote that sounds similar. It allows items in the dropdown list to be highlighted (text in red). The highlighted state is maintained when the dropdown list disappears, though in this implementation a selected item has highlighting turned off (the idea was that the items are things the user needed to see, once the user had selected a item, it no longer needed to be highlighted).
    For this to work all the items in your list must implement HighlightingComboBox.Highlightable.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    * An extension to JComboBox that allows items to be "highlighted"
    * (if they implement the HighlightingComboBox.Highlightable interface).
    * Highlighted items are shown in red. Highlighting is turned off when
    * the item is first selected. Items not impleneting that interface are
    * displayed normally. The drop-down list is rendered the same
    * regardless of the font property of the components, it is therefore
    * possible to set that property to, say, a huge, fancy font without the
    * drop-down panel being affected.
    public class HighlightingComboBox extends JComboBox
                                      implements ActionListener {
        public HighlightingComboBox() {
            super();
            addActionListener(this);
            setRenderer(new FancyRenderer());
        public HighlightingComboBox(Object[] os) {
            super(os);
            this.addActionListener(this);
            setRenderer(new FancyRenderer());
        public void actionPerformed(java.awt.event.ActionEvent ae) {
            if (getSelectedItem() instanceof Highlightable)
                ((Highlightable)getSelectedItem()).setHighlighted(false);
        private static class FancyRenderer extends JLabel
                                           implements ListCellRenderer {
            public java.awt.Component getListCellRendererComponent(
                    javax.swing.JList list,
                    Object value,
                    int index,
                    boolean isSelected,
                    boolean cellHasFocus) {
                setText(value.toString());
                if ((value instanceof Highlightable)
                           && (((Highlightable)value).isHighlighted())) {
                    setForeground(Color.red);
                } else {
                    setForeground(Color.black);
                setBackground(isSelected ? Color.yellow : Color.white);
                setForeground(Color.black);
                return this;
         * Objects that implement this interface can be
         * highlighted on a HighlightingComboBox.
        public interface Highlightable {
            public boolean isHighlighted();
            public void setHighlighted(boolean flag);
    }

  • Keeping id's of list for JCombobox

    Hi,
    i'm filling a JCombobox with database values (Strings) of a table. Every string has an internal ID, which i use to store in other tables.. My problem is the following: i know i can detect what the user selected (getSelectedIndex() and getSelectedValue()), but what does that mean to me. GetSelectedIndex is only a number and GetSelectedValue is the text in de combobox, which i only a text i don't want to store. What i do want to know, is the internal ID behind that value. I don't want to retrieve my database again because i know the String of the table to get the internal ID.
    I solved my problem by extending a JCombobox and keeping track of my internal ID's in a int[], but i don't know if this is the best solution.
    Am I missing something? Is there a very simple solution for my problem?
    Greetz
    Peesjee

    A JComboBox can take as it's model more than just an array or vector or Strings, it can also take an array or vector of objects, and this is important. What is displayed in the combobox is whatever the class's object would display in the class's toString method override. So, if you have a combobox of objects of a class, and you can extract the selected object, you can extract that object's data. As a simple example, see below:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    class Fubar1 extends JPanel
        Fubar1()
            Data[] dataArray =
                new Data("Aaron", 34),
                new Data("Bill", 264),
                new Data("Charlie", 3421),
                new Data("Dennis", 2919),
                new Data("Edward", 9),
            JComboBox combobox = new JComboBox(dataArray);
            combobox.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    JComboBox cb = (JComboBox)e.getSource();
                    Data myData = (Data)cb.getSelectedItem();
                    System.out.println(myData.getId()); // display the id of the selected item
            add(combobox);
        private class Data
            String text;
            int id;
            Data(String text, int id)
                this.text = text;
                this.id = id;
            public String getText()
                return text;
            public int getId()
                return id;
            @Override
            public String toString()
                // very important.  this is what shows in combobox
                return text;
        // show the jframe in a thread-safe manner
        private static void createAndShowUI()
            JFrame frame = new JFrame("Fubar");
            frame.getContentPane().add(new Fubar1());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            java.awt.EventQueue.invokeLater(new Runnable()
                public void run()
                    createAndShowUI();
    }

  • How to create a JComboBox with Dates???

    Hi... I need to create a JComboBox with Date elements...
    For example: from "Jan-01-2007" to "Mar-02-2007"
    Jan-01-2007
    Jan-02-2007
    Jan-03-2007
    Mar-01-2007
    Mar-02-2007
    Anyone know how to do it???
    Regards...

    //here is an example how to get the date
    //I think this might help you!!!
    import java.text.DateFormat;
    import java.util.Date;
    public class DateFormatExample1 {
        public static void main(String[] args) {
            // Make a new Date object. It will be initialized to the current time.
            Date now = new Date();
            // See what toString() returns
            System.out.println(" 1. " + now.toString());
            // Next, try the default DateFormat
            System.out.println(" 2. " + DateFormat.getInstance().format(now));
            // And the default time and date-time DateFormats
            System.out.println(" 3. " + DateFormat.getTimeInstance().format(now));
            System.out.println(" 4. " +
                DateFormat.getDateTimeInstance().format(now));
            // Next, try the short, medium and long variants of the
            // default time format
            System.out.println(" 5. " +
                DateFormat.getTimeInstance(DateFormat.SHORT).format(now));
            System.out.println(" 6. " +
                DateFormat.getTimeInstance(DateFormat.MEDIUM).format(now));
            System.out.println(" 7. " +
                DateFormat.getTimeInstance(DateFormat.LONG).format(now));
            // For the default date-time format, the length of both the
            // date and time elements can be specified. Here are some examples:
            System.out.println(" 8. " + DateFormat.getDateTimeInstance(
                DateFormat.SHORT, DateFormat.SHORT).format(now));
            System.out.println(" 9. " + DateFormat.getDateTimeInstance(
                DateFormat.MEDIUM, DateFormat.SHORT).format(now));
            System.out.println("10. " + DateFormat.getDateTimeInstance(
                DateFormat.LONG, DateFormat.LONG).format(now));
    }

  • Horizontal scrollbar for JComboBox - Not workable under Mac

    By referring to this thread Re: Horizontal scrollbar for JComboBox across multiple look and feel I try to provide horizontal scroll bar for JComboBox to my clients.
    private void adjustScrollBar() {
        //if (this.getItemCount() == 0) return;
        Object comp = this.getUI().getAccessibleChild(this, 0);
        if (!(comp instanceof JPopupMenu)) {
            return;
        JPopupMenu popup = (JPopupMenu) comp;
        // Works fine under Windows and Ubuntu Linux
        // However, in OSX 10.6.4
        // javax.swing.Box$Filler cannot be cast to javax.swing.JScrollPane
        JScrollPane scrollPane = (JScrollPane) popup.getComponent(0);
        scrollPane.setHorizontalScrollBar(new JScrollBar(JScrollBar.HORIZONTAL));
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    }The above code will cause ClassException under OSX 10.6.4. (Works fine for Windows and Linux)
    Any suggestion to resolve this problem. Sorry. I do not have a Mac machine. Hence, can't experiment out much with it.
    Thanks

    The following code works quite well for me.
        private void adjustScrollBar() {
            final int max_search = 8;
            // i < max_search is just a safe guard when getAccessibleChildrenCount
            // returns an arbitary large number. 8 is magic number
            JPopupMenu popup = null;
            for (int i = 0, count = this.getUI().getAccessibleChildrenCount(this); i < count && i < max_search; i++) {
                Object o = this.getUI().getAccessibleChild(this, i);
                if (o instanceof JPopupMenu) {
                    popup = (JPopupMenu)o;
                    break;
            if (popup == null) {
                return;
            JScrollPane scrollPane = null;
            for (int i = 0, count = popup.getComponentCount(); i < count && i < max_search; i++) {
                Component c = popup.getComponent(i);
                if (c instanceof JScrollPane) {
                    scrollPane = (JScrollPane)c;
                    break;
            if (scrollPane == null) {
                return;
            scrollPane.setHorizontalScrollBar(new JScrollBar(JScrollBar.HORIZONTAL));
            scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        }

  • Fill JComboBox with Vector from database

    Hi there,
    I have a problem with filling a JComboBox with data from a database. I can print the data in the console, but it seems to be impossible to do it in a ComboBox ...
    I tried this:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    *package client;*
    *import data.Raum;*
    *import data.RaumImpl;*
    *import java.net.MalformedURLException;*
    *import java.rmi.Naming;*
    *import java.rmi.NotBoundException;*
    *import java.rmi.RemoteException;*
    *import java.sql.SQLException;*
    *import javax.swing.JComboBox;*
    *import javax.swing.JFrame;*
    *import java.util.Vector;*
    *import verwaltung.*;
    import server.DraServer;
    * @author philipp
    public class ComboBox extends JFrame
        ComboBox(String title) throws RemoteException, SQLException, NullPointerException, MalformedURLException, NotBoundException {
        super(title);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        DraVerwaltung verwaltung = (DraVerwaltung) Naming.lookup ("rmi://localhost/DRA");
        System.out.println("Remote object created...");
        Vector raeume = verwaltung.RaumAusleser();
        Raum r;
        for (int i = 0; i < raeume.size(); i++)
            r = (Raum)raeume.elementAt(i);
    //      System.out.println ("Raum: " + r.getRaumname());
    //      System.out.println ("Raumid: " + r.getIdRaum());
         JComboBox jcb = new JComboBox(r.getRaumname());
        getContentPane().add(jcb);
        setSize(200, 50);
        setVisible(true);      
      public static void main(String[] args) throws RemoteException, SQLException, NullPointerException, MalformedURLException, NotBoundException {
        new ComboBox("Test");
    }In this case I get the following for JComboBox (line 44):
    "cannot find symbol
    symbol: constructor JComboBox(java.lang.string)
    location: class javax.swing.JComboBox"
    I tried:
    -> change "JComboBox jcb = new JComboBox(r.getRaumname());" to "JComboBox jcb = new JComboBox(raeume);"
    then I got the JComboBox, but with ... I don't know how to describe the content. It seems like a (very long) reference.
    All other tries can't be tested, because I got the problem with constructor again.
    I'm happy for an early response.
    Regards

    Now, it works!
    It looks like that:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package client;
    import data.Raum;
    import data.RaumImpl;
    import java.net.MalformedURLException;
    import java.rmi.Naming;
    import java.rmi.NotBoundException;
    import java.rmi.RemoteException;
    import java.sql.SQLException;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import java.util.Vector;
    import verwaltung.*;
    import server.DraServer;
    * @author philipp
    public class ComboBox extends JFrame
        ComboBox(String title) throws RemoteException, SQLException, NullPointerException, MalformedURLException, NotBoundException {
        super(title);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        DraVerwaltung verwaltung = (DraVerwaltung) Naming.lookup ("rmi://localhost/DRA");
        System.out.println("Remote object created...");
        Vector raeume = verwaltung.RaumAusleser();
        Raum r = new RaumImpl();
        Vector vJcb = new Vector();
        for (int i = 0; i < raeume.size();i++){
            r = (Raum)raeume.elementAt(i); 
            vJcb.add(r.getRaumname());
        JComboBox jcb = new JComboBox(vJcb);
        getContentPane().add(jcb);
        setSize(200, 50);
        setVisible(true);     
        public static void main(String[] args) throws RemoteException, SQLException, NullPointerException, MalformedURLException, NotBoundException {
           new ComboBox("Combo box Demo1");
    }Thanks in advantage to all!

  • How can I fill a JComboBox with a ResultSet?

    I want to fill a JComboBox with the data in ResultSet. What�s the better way to do this? Can I convert a RecordSet to a Vector and use the vector in JComboBox constructor?
    Thanks for any help.
    Renato

    Prova cosi:
    myComboBox = new JComboBox();
    ArrayList items = new ArrayList();
    ResultSet result = conn.executeQuery("SELECT BLABLA FROM BLABLA");
    while (result.next())
    items.add(result.getString(1));
    result.close();
    myComboBox.setModel(new DefaultComboBoxModel(items.toArray()));
    E' molto pi� efficiente che aggiungere gli item alla combo uno alla volta.
    G.M.

  • How can i populate the Jcombobox with the data from my jpa list? Desperate

    I need to populate my jcombobox with data from my jpa. This is my first time trying this and i just need some sample or a quick solution to this. Thanks in advance
    <code>
    public static MyNames myNames() {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("JavaTrialsPU");
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    Query q = em.createNamedQuery("MyNames.findAll");
    MyNames n = (MyNames) q.getResultList();
    return n;
    public static void myCombo() {       
    comboBox = new JComboBox(????--how can i make the jcombobox display my myNames() list--?????);
    frame.add(comboBox, BorderLayout.PAGE_START);
    </code>

    Implement toString() on your entity to return whatever you want to use as a label for the combobox.
    Your need for quick solutions is very destructive to your learning process. In stead take the time and read around a little. Swing happens to have an excellent tutorial with many example programs readily available for you to pick through:
    http://docs.oracle.com/javase/tutorial/uiswing/
    And PS: you need to use \ tags in this forum.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • ADF DataControl for WebService with unexpected blank objects

    Hello experts!
    I'm developing for BPM Suite 11.1.1.5 PS4 Feature Pack using JDeveloper 11.1.1.5
    I am currently using Data Controls for web services that interact with SAP; I can retrieve information successfully displaying items in tables and selectOneChoice lists without a problem.
    There are no Java classes for the Data Controls, everything is handled by the XML files created by JDeveloper.
    The issue happens when creating the input parameters for a web service that updates data in the remote system. The web service has complex types with lists of complex types. I am currently using the iterator for the items on the complex types to create rows and add values to those rows. The problem is that for some reason the input for those lists always contain one extra object with no data (this was identified with the help of tcpmon).
    I'll use the example of the Barcodelist list of items; the corresponding iterators are BarcodelistIterator and itemIterator2. There's also an action binding for the creation of a new row.
    The bindings:
    <accessorIterator MasterBinding="ZPostInvoiceAndAttachment_parametersIterator"
    Binds="Barcodelist" RangeSize="25" DataControl="sapPost"
    BeanClass="sapPost.Types.ZPostInvoiceAndAttachment.Barcodelist"
    id="BarcodelistIterator"/>
    <accessorIterator id="itemIterator2" MasterBinding="BarcodelistIterator"
    Binds="item" RangeSize="25" DataControl="sapPost"
    BeanClass="sapPost.Types.ZPostInvoiceAndAttachment.Barcodelist.item"/>
    <action IterBinding="itemIterator2" id="CreateInsert2"
    InstanceName="sapPost.Types.ZPostInvoiceAndAttachment.Barcodelist.item"
    DataControl="sapPost" RequiresUpdateModel="true"
    Action="createRow"/>
    This is the definition for item.xml:
    <?xml version="1.0" encoding="UTF-8" ?>
    <JavaBean xmlns="http://xmlns.oracle.com/adfm/beanmodel" version="11.1.1.60.13"
    id="item"
    Package="sapPost.Types.ZPostInvoiceAndAttachment.Barcodelist"
    BeanClass="sapPost.Types.ZPostInvoiceAndAttachment.Barcodelist.item"
    isJavaBased="false">
    <Attribute Name="Barcode" IsNotNull="true" Type="java.lang.String"/>
    <Attribute Name="BarcodeId" IsNotNull="true" Type="java.lang.String"/>
    <Attribute Name="Contrep" IsNotNull="true" Type="java.lang.String"/>
    <Attribute Name="Docid" IsNotNull="true" Type="java.lang.String"/>
    <Attribute Name="Ardate" IsNotNull="true" Type="java.lang.String"/>
    <Attribute Name="Doctype" IsNotNull="true" Type="java.lang.String"/>
    </JavaBean>
    This is the code to insert a single item in the list. I clear all items for the iterator with a method I will show below
    //Barcode List
    DCIteratorBinding itr4 = ADFUtils.findIterator("itemIterator2");
    ADFUtils.clearAllRowsForIterator(itr4);
    OperationBinding createBarcodeList = ADFUtils.findOperation("CreateInsert2");
    createBarcodeList.execute();
    Row barcodeRow = itr4.getCurrentRow();
    barcodeRow.setAttribute("Barcode", "20120208114025");
    barcodeRow.setAttribute("BarcodeId", "01");
    barcodeRow.setAttribute("Contrep", "ZT"); //ZT for Test Documentum, ZD for Production
    barcodeRow.setAttribute("Docid", "DCTM3701E24080000D9A");
    barcodeRow.setAttribute("Ardate", "2011-09-01");
    barcodeRow.setAttribute("Doctype", "PDF");
    ADFUtils.clearAllRowsForIterator method:
    public static void clearAllRowsForIterator(DCIteratorBinding itr) {
    Row[] allItems = itr.getAllRowsInRange();
    for( int i = 0; i < allItems.length; i++ ) {
    itr.removeCurrentRow();
    The code below is implemented in an ActionListener for a button which calls the web service method:
    public void postToSAP(ActionEvent actionEvent) {
    setPostInput(); //sets all input parameters
    OperationBinding op = ADFUtils.findOperation("ZPostInvoiceAndAttachment");
    Object returned = op.execute();
    When I monitor what is being sent in the SOAP envelop using tcpmon I get 2 items for the barcodelist (and similarly an additional blank item for every list in the input parameters):
         <Barcodelist>
              <item>
                   <Barcode>20120208114025</Barcode>
                   <BarcodeId>01</BarcodeId>
                   <Contrep>ZT</Contrep>
                   <Docid>DCTM3701E24080000D9A</Docid>
                   <Ardate>2011-09-01</Ardate>
                   <Doctype>PDF</Doctype>
              </item>
              <item>
                   <Barcode/><BarcodeId/><Contrep/><Docid/><Ardate/><Doctype/>
              </item>
         </Barcodelist>
    This causes the web service to return an error as there's a blank item in the list.
    I have checked the number of rows in the barcode list before and after the web service call and it is always 1. I can't find where this blank item is coming from. I searched the web but all I found which would address this would be to implement java classes; but the goal here would be to achieve this with as less java programming effort as possible.
    Any help is greatly appreciated.
    Bruno

    user1113055 wrote:
    ... the consequent adaptation of the existing JSPXs based on the previous definition of the view objects was quite painful: i found very hard to reflect the changes to the JSPXs and, in some cases, i had to rewrite the pages from scratch! You will need to be more specific about the issues that you have encountered. Synchronization and refactoring is supported in JDeveloper for the model, the view and the controller. For what it's worth, take a look at these entry-level posts that could provide some additional inside:
    http://jdeveloperfaq.blogspot.com/2010/02/faq-15-how-to-synchronize-adf-entity.html
    http://jdeveloperfaq.blogspot.com/2010/04/faq-20-how-to-refactor-adf-components.html

  • JComboBox with checkboxes - how to ?

    How can I implement a JComboBox with JChecBoxes as elements ?

    my first guess:
    import java.awt.BorderLayout;
    import java.awt.Component;
    import javax.swing.JCheckBox;
    import javax.swing.JList;
    import javax.swing.ListCellRenderer;
    public class CheckListCellRenderer extends JCheckBox implements
            ListCellRenderer {
        public CheckListCellRenderer() {
            setLayout(new BorderLayout());
        public Component getListCellRendererComponent(JList list, Object value,
                int index, boolean isSelected, boolean cellHasFocus) {
            return (Component) value;
    }The problem is the checkboxes are not editable....

  • JComboBox with type-ahead capabilities?

    Hi, guys:
    I have a JComboBox with a list of string items. Since the list is very long (with several hundred of items), I would like to implement someting like
    the following so that use does not have to scroll down the list to search for an item: when user types the starting letter of an item, it should locate the first item starting with this letter. IE address bar has this kind of type-ahead capability
    I am wondering how I can do the similar thing using Swing JComboBox?
    regards,

    Thanks for your sample, it works.
    Here is the "old code" I am talking about. I slightly modified it and add a main method. It looks fine, but it just does not work. I really have no clue why this one just does not work:
    import java.awt.event.KeyListener;
    import java.util.Vector;
    import javax.swing.ComboBoxModel;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class SelectableComboBox
        extends JComboBox
        protected boolean required;
        protected JLabel fieldLabel;
        public SelectableComboBox()
            super();
        public SelectableComboBox( final boolean required )
            super();
            this.required = required;
        public SelectableComboBox( final ComboBoxModel model )
            super( model );
        public SelectableComboBox( final Object[] objects )
            super( objects );
        public SelectableComboBox( final Vector v )
            super( v );
        public void setEnabled( final boolean b )
            super.setEnabled( b );
            if( this.fieldLabel != null )
                this.fieldLabel.setEnabled( b );
        public JLabel getLabel()
            return this.fieldLabel;
        public void setLabel( final JLabel l )
            this.fieldLabel = l;
        public JLabel createLabel( final String s )
            this.fieldLabel = new JLabel( s );
            return this.fieldLabel;
        public boolean isEquals( final String s )
            if( this.fieldLabel != null && this.fieldLabel.getText() != null
                    && s != null )
                return s.equals( this.fieldLabel.getText() );
            return false;
        public String toString()
            if( this.fieldLabel != null && this.fieldLabel.getText() != null
                    && this.fieldLabel.getText().length() > 0 )
                return this.fieldLabel.getText();
            return super.toString();
        public void setRequired( final boolean req )
            this.required = req;
        public boolean isRequired()
            return this.required;
        public JTextField getTextField()
            int total = getComponentCount();
            JTextField field = null;
            for( int i = 0; i < total; i++ )
                if( getComponent( i ) instanceof JTextField )
                    field = (JTextField) getComponent( i );
                    break;
            return field;
        public JButton getButton()
            int total = getComponentCount();
            JButton button = null;
            for( int i = 0; i < total; i++ )
                if( getComponent( i ) instanceof JButton )
                    button = (JButton) getComponent( i );
                    break;
            return button;
        public void addKeyListener( final KeyListener l )
            JTextField field = getTextField();
            if( field != null )
                field.addKeyListener( l );
        public void removeKeyListener( final KeyListener l )
            JTextField field = getTextField();
            if( field != null )
                field.removeKeyListener( l );
        public static void main( final String[] args )
            JFrame fr = new JFrame();
            fr.setSize(150,75);
              fr.setLocation(400,300);
              fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel jp = new JPanel();
              SelectableComboBox cb = new SelectableComboBox();
            cb.addItem( "Abc" );
            cb.addItem( "cbs" );
            cb.addItem( "nbc" );
            cb.addItem( "fox" );
            cb.addItem( "wb" );
            cb.addItem( "ycc" );
              jp.add(cb);
              fr.getContentPane().add(jp);
            fr.pack();
            fr.setVisible( true );
    }Appreciate your help.

  • Jcombobox with lovbinding very slow

    I've a simple Jclient with a JcomboBox. In the combobox's model I choosed a LOV view object containing about 5000 records. The trouble is that when I start the application, the form doesn't appear even if I wait for 10 minutes! I noticed a big network traffic between client and db so I suspect some bug in the LOV bindind code.
    I'm right ?
    Thanks
    Massimo Marolda

    I've a simple Jclient with a JcomboBox. In the combobox's model I choosed a LOV view object containing about 5000 records. The trouble is that when I start the application, the form doesn't appear even if I wait for 10 minutes! I noticed a big network traffic between client and db so I suspect some bug in the LOV bindind code.
    I'm right ?Perhaps you're not using the right control. ComboBox is not designed to work with thousands or rows. It's a control that works best when you have a few choices (say in the order of 10s). For LOVs with more than that you may choose a button binding that brings up the Lov in a popup window.
    By default Combobox needs all the data for it's display right away, to calculate the drop down size/scroll size, and that's why you're seeing a tremendous performance hit. But 10 minutes..... That's perhaps due to persistent collection kickin in for spill-to-disk. For more on how to control spill-to-disk parameters, read a howto at
    http://forums.oracle.com/forums/message.jsp?id=902552
    Thanks
    Massimo Marolda

Maybe you are looking for

  • Sync between iPhone and iPad failed spectacularly

    The equipment: iPad Mini Retina iPhone 5S The OS: 8.1.3 (on both) The Objective: So my wife has an iPad and an iPhone. She's been using Podcasts on the iPhone for quite some time, and hasn't had a problem with it for quite a while now - it seems most

  • Cannot open .xls or .doc files

    I have office 2008 updated to the latest version operating on a mac osx 10.5.8. I cannot open xls or doc files. I get the messages "file cannot be opened" and "file blocked". Have tried - opening via right click and through the programs themselves -

  • Error in AUC Settlement (Urgent)

    Hello Every body, I got an error while posting the AUC Capitalization in the settlement rule i have given 100% and amount which needs to be capitalized can also be seen in the Asset Explorer ....the error is as follows.. <u><b>Error:</b></u> Line Ite

  • Why I can't watch you tube videos on my BB

     I can't watch youtube videos on my blackberry, why?

  • How to change password in ESS

    Hi all,    Is there any facility to change password in ESS? Or this facility is available in HRUSER transaction ? Thanks & regard, Sameer