JCombobox with a JTable as Popup

Hi!
I will ask if it's possible create a JCombobox that show a JTable instead the popup at the mouse click event.
I've drew a JComboBox and a JTable under it but I don't know how can I stop the popup menu.
Thanks for the help.

you will have to make JavaBean Component for the same..
you may have to use of
- JTextFiend
- JButton
- JTable
- JLayerPane
with the specific event as you required..
Timir

Similar Messages

  • Editable JComboBox in a JTable

    I posted my problem into the "Java Essentials/Java programming" forum but it would be much better if I'd posted it here into the swing theme :).
    Here it is what I posted:
    Funky_1321
    Posts:8
    Registered: 2/22/06
    editable JComboBox in a JTable
    Oct 21, 2006 1:32 PM
    Click to email this message
    Hello!
    Yesterday I posted a problem, solved it and there's another one, referring the same theme.
    So it's about a editable JComboBox with autocomplete function. The combo is a JTables cellEditors component. So it's in a table. So when the user presses the enter key to select an item from the JComboBox drop down menu, I can't get which item is it, not even which index has the item in the list. If for exemple the JComboBox isn't in a table but is added on a JPanel, it works fine. So I want to get the selectedItem in the actionPerformed method implemented in the combo box. I always get null instead of the item.
    Oh... if user picks up some item in the JComboBox-s list with the mouse, it's working fine but I want that it could be picked up with the enter key.
    Any solutions appreciated!
    Thanks, Tilen
    YAT_Archivist
    Posts:1,321
    Registered: 13/08/05
    Re: editable JComboBox in a JTable
    Oct 21, 2006 1:55 PM (reply 1 of 2)
    Click to email this message
    I suggest that you distill your current code into a simple class which has the following attributes:
    1. It can be copied and pasted and will compile straight out.
    2. It has a main method which brings up a simple example frame.
    3. It's no more than 50 lines long.
    4. It demonstrates accurately what you've currently got working.
    Without that it's hard to know exactly what you're currently doing, and requires a significant investment of time for someone who hasn't already solved this problem before to attempt to help. I'm not saying that you won't get help if you don't post a simple demo class, but it will significantly improve your chances.
    Funky_1321
    Posts:8
    Registered: 2/22/06
    Re: editable JComboBox in a JTable
    Oct 21, 2006 2:11 PM (reply 2 of 2)
    Click to email this message
    Okay ... I'll write the code in short format:
    class acJComboBox extends JComboBox {
      public acJComboBox() {
        this.setEditable(true);
        this.setSelectedItem("");
        this.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) {
         // ... code code code
         // that's tricky ... the method getSelectedItem() always returns null - remember; the acJComboBox is in a JTable!
         if (e.getKeyCode() == 10 && new String((String)getEditor().getItem()).length() != 0) { getEditor().setItem(getSelectedItem()); }
    }And something more ... adding the acJComboBox into the JTable:
    TableColumn column = someTable.getColumn(0);
    column.setCellEditor(new DefaultCellEditor(new acJComboBox());
    So if the user presses the enter key to pick up an item in the combo box drop down menu, it should set the editors item to the selected item from the drop down menu (
    getEditor().setItem(getSelectedItem());
    When the acJComboBox is on a usual JPanel, it does fine, but if it's in the JTable, it doesn't (getSelectedItem() always returns null).
    Hope I described the problem well now ;).

    Okay look ... I couldn't write a shorter code just for an example. I thought that my problem could be understoodable just in mind. However ... type in the first combo box the letter "i" and then select some item from the list with pressing the enter key. Do the same in the 2nd combo box who's in the JTable ... the user just can't select that way if the same combo is in the JTable. Why? Thanks alot for future help!
    the code:
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.util.Vector;
    import javax.swing.DefaultCellEditor;
    import javax.swing.DefaultComboBoxModel;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableColumn;
    class Example extends JFrame {
        private String[] columns = { "1", "2", "3" };
        private String[][] rows = {};
        private DefaultTableModel model = new DefaultTableModel(rows, columns);
        private JTable table = new JTable(model);
        private JScrollPane jsp = new JScrollPane(table);
        private acJComboBox jcb1 = new acJComboBox();
        private acJComboBox jcb2 = new acJComboBox();
        public Example() {
            // initialize JFrame
            this.setLayout(null);
            this.setLocation(150, 30);
            this.setSize(300, 300);
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
            // initialize JFrame
            // initialize components
            Vector<String> v1 = new Vector<String>();
            v1.add("item1");
            v1.add("item2");
            v1.add("item3");
            jcb1.setData(v1);
            jcb2.setData(v1);
            jcb1.setBounds(30, 30, 120, 20);
            jsp.setBounds(30, 70, 250, 100);
            add(jcb1);
            add(jsp);
            TableColumn column = table.getColumnModel().getColumn(0);
            column.setCellEditor(new DefaultCellEditor(jcb2));
            Object[] data = { "", "", "" };
            model.addRow(data);
            // initialize components
            this.setVisible(true);
        public static void main(String[] args) {
            Example comboIssue = new Example();
    class acJComboBox extends JComboBox {
        private Vector<String> data = new Vector<String>();
        private void init() {
            this.setEditable(true);
            this.setSelectedItem("");
            this.setData(this.data);
            this.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) {
                        if (e.getKeyCode() != 38 && e.getKeyCode() != 40) {
                            String a = getEditor().getItem().toString();
                            setModel(new DefaultComboBoxModel());
                            int st = 0;
                            for (int i = 0; i < getData().size(); i++) {
                                String str1 = a.toUpperCase();
                                String tmp = (String)getData().get(i).toUpperCase();
                                if (str1.length() <= tmp.length()) {
                                    String str2 = tmp.substring(0, str1.length());
                                    if (str1.equals(str2)) {
                                        DefaultComboBoxModel model = (DefaultComboBoxModel)getModel();
                                        model.insertElementAt(getData().get(i), getItemCount());
                                        st++;
                            getEditor().setItem(new String(a));
                            JTextField jtf = (JTextField)e.getSource();
                            jtf.setCaretPosition(jtf.getDocument().getLength());
                            hidePopup();
                            if (st != 0 && e.getKeyCode() != 10 && new String((String)getEditor().getItem()).length() != 0) { showPopup(); }
                            if (e.getKeyCode() == 10 && new String((String)getEditor().getItem()).length() != 0) { getSelectedItem(); }
                            if (new String((String)getEditor().getItem()).length() == 0) { whenEmpty(); }
            this.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) {
                hidePopup();
        // - constructors -
        public acJComboBox() {
            init();
        public acJComboBox(Vector<String> data) {
            this.data = data;
            init();
        // - constructors -
        // - interface -
        public void whenEmpty() { } // implement if needed
        public void setData(Vector<String> data) {
            this.data = data;
            for (int i = 0; i < data.size(); i++) {
                this.addItem(data.get(i));
        public Vector<String> getData() {
            return this.data;
        // - interface -
    }

  • JTable JCombox popup on click in table cell

    What is the recommended way of making a JComboBox that is in a JTable cell popup when the user clicks once anywhere in the cell?
    The popup is actually a calendar that works fine if the user clicks on the spot where the button shows up in the cell but sets the focus in the text box of the JComboBox is the click is anywhere else in the cell and the popup doesn't sho in that case. To get to the popup requires a click on the button.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test extends JFrame {
      public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        String[] head = {"One","Two","Three"};
        String[][] data = {{"R1-C1","R1-C2","R1-C3"},
                           {"R2-C1","R2-C2","R2-C3"},
                           {"R3-C1","R3-C2","R3-C3"}};
        JTable jt = new JTable(data, head);
        content.add(new JScrollPane(jt), BorderLayout.CENTER);
        JComboBox jcb = new JComboBox(head);
        jcb.addFocusListener(new FocusAdapter() {
          public void focusGained(FocusEvent fe) {
            ((JComboBox)fe.getSource()).showPopup();
        jt.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(jcb));
        setSize(200, 200);
        setVisible(true);
      public static void main(String[] args) { new Test(); }
    }

  • JComboBox HTML select JTable editor

    I want to use a JComboBox in a JTable cell as editor and renderer. The JComboBox should work just like a HTML select component with a value and a description. When the user changes selection in the JComboBox instead of the description the value should be set as the cell value in the JTable. Can somebody help me with information about how I can do this?
    Thanks.

    Check out this [url http://forum.java.sun.com/thread.jsp?forum=57&thread=478229]example. You store an Object in the cell that contains both the value and description.

  • JComboBox with Horizontal ScrollBar

    Hi all,
    I created this custom ComboBox:
    import com.sun.java.swing.*;
    import com.sun.java.swing.plaf.basic.*;
    public class myCombo extends JComboBox{
        public myCombo(){
            super();
            setUI(new myComboUI());
        public class myComboUI extends BasicComboBoxUI{
            protected ComboPopup createPopup(){
                BasicComboPopup popup = new BasicComboPopup(comboBox){
                    protected JScrollPane createScroller() {
                            return new JScrollPane( list, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED );
                return popup;
      {code}
    When i add this ComboBox to a Frame, it has a look and feel diffrent from the others component !
    How to resolve that ?
    Regards
    Jack                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    [removed]
    Just another cross poster.
    [http://www.coderanch.com/t/432788/Swing-AWT-SWT-JFace/java/JComboBox-with-horizontall-scroll-bar]
    Edited by: Darryl.Burke

  • Setting color of an item in a Jcombobox in a JTable when editing

    Hello,
    I have a situation where I have a JCombobox in a JTable . The JCombobox is non-editable. The items within the combobox are colored in pink or blue in order to help the user differentiate between the two categories that are in the list.
    But the problem is that when the user is on that cell and is just typing the first letter(s) in the combobox, he does see the item starting with that letter(s) but that item is not shown as colored. However, if the user clicks on the combobox with a mouse, the list pops-up and the items are shown as colored. I want the first part to work where the user can just use keyboard and see the items as colored in that cell itself. By default, currently when the row is selected the foreground is white and background is black. I want that particularly when this combobox has focus and an item is selected, the foreground should be of the same color as the color of the item.
    Can someone help?
    Thanks a lot in advance.

    Additional information on above:
    I associate a customized renderer with the column of my table for which i want to set the colors.
    TableColumn tc6 = jTableDRS.getColumnModel().getColumn(myDRSModel.FINANCECODE_COLUMN);
    tc6.setCellRenderer(new ColorRenderer());
    here is the renderer that I am using...
    public class ColorRenderer extends JLabel implements TableCellRenderer {
    protected Border noFocusBorder;
    public ColorRenderer() {
    noFocusBorder = new EmptyBorder(1, 2, 1, 2);
    setOpaque(true);
    setBorder(noFocusBorder);
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column) {
    Color foreground = null;
    Color background = null;
    Font font = null;
    if(column == myDRSModel.FINANCECODE_COLUMN)
    setFont((font != null) ? font : table.getFont());
    String str = (String)value.toString();
    if (!str.equalsIgnoreCase("SELECT ONE")) {
    int y = financedesc.indexOf(str);
    if((payreceiveind.get(y).toString()).equals("R")){
    setForeground(Color.RED);
    } else if((payreceiveind.get(y).toString()).equals("P")){
    setForeground(new Color(147,112,240));
    if(isSelected)
    if((payreceiveind.get(y).toString()).equals("R")){
    setForeground(Color.RED);
    } else if((payreceiveind.get(y).toString()).equals("P")){
    setForeground(new Color(147,112,240));
    setBackground(table.getSelectionBackground());
    else{
    setBackground(table.getBackground());
    else
    if(isSelected)
    setForeground(table.getSelectionForeground());
    setBackground(table.getSelectionBackground());
    else
    setForeground(table.getForeground());
    setBackground(table.getBackground());
    setValue(value);
    return this;
    protected void setValue(Object value) {
    setText((value == null) ? "" : value.toString());
    }

  • Problems with a JTable

    Hello folks,
    i got two problems with a JTable.
    1. how do I change the size of a table header???
    2. I know that it is possible to set different column-sizes. The problem in my table is that I don't know how long some cells are. In this case, I want to to get the biggest cell of one column and set its size as the default size of that specific column.
    Is that possilbe?
    Hopefully you can help me out,
    thank you

    A JTableHeader is just another Component, so you ought to be able to set its size like you would
    any other component; however, since its function is to act as a header for a table, it might constrain
    itself to fit the table.
    In order to size the column to fit the largest cell, for each row, go through each column and get the
    renderer component for that column (which configures the component for rendering) and get the width
    of that component. If that's bigger than the column's current width, set its width and preferred width.
    You'll also want to check the renderer component width for the header to make sure the header doesn't
    get truncated if the column doesn't have a cell whose value is longer than the header.
    : jay

  • 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));
    }

  • BUG: Popup in page fragment; with many regions and popup binded to backing.

    BUG: Popup in page fragment; with many regions and popup or parent binded to backing bean.
    JDEV11.1.2.1 Popup will not popup.(sometimes works if using RichPopup.Show() in backing bean Java code.)
    I have a bug (Popup will not popup)that only happens when I have more than one of the same region.
    And I have a popup in the page fragment is binded to backing bean.
    My SR guy is out today but we plan to enter one.
    test.jspx
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
              xmlns:f="http://java.sun.com/jsf/core">
        <jsp:directive.page contentType="text/html;charset=UTF-8"/>
        <f:view>
            <af:document title="test" id="d1">
                <af:form id="f1">
                    <af:panelGroupLayout id="pgl1" layout="horizontal">
                        <af:outputText value="BUG JDEV11.1.2.1 and IE7. Broken Popup! If I have a jsff fragment and I have many regions of this fragment."
                                       id="ot2"/>
                        <af:outputText value="Inside the fragment I have a popup. If that popup or its parent are binded to a Backing Bean the popup doesn't work."
                                       id="ot1"/>
                    </af:panelGroupLayout>
                    <!-- with a single region it also works (with bindings in place in fragment). -->
                    <af:region value="#{bindings.taskflowemp1.regionModel}" id="r1"/>
                    <af:region value="#{bindings.taskflowemp2.regionModel}" id="r2"/>    
                    <!--
                    <af:region value="#{bindings.taskflowemp3.regionModel}" id="r3"/>
                    <af:region value="#{bindings.taskflowemp4.regionModel}" id="r4"/>
                    -->
                </af:form>
            </af:document>
        </f:view>
    </jsp:root>region.jsff
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
              xmlns:f="http://java.sun.com/jsf/core">
      <af:group id="g1">
      <!-- If I remove the binding for popop or popup group, the popup works fine. -->
    <!--Working code here
        <af:group id="g2">
          <af:popup childCreation="deferred" autoCancel="disabled" id="p1" >
        -->
           <!-- Problem code here   -->
        <af:group id="g2" binding="#{TestBean.popupGroup}">
          <af:popup childCreation="deferred" autoCancel="disabled" id="p1" binding="#{TestBean.testPopup}"> 
            <!-- End problem code -->
            <af:dialog id="d2" title="Dialog Title">
              <f:facet name="buttonBar"/>
              <af:outputText value="Dialog Contents" id="ot100"/>
            </af:dialog>
          </af:popup>
        </af:group>
        <af:panelGroupLayout id="pgl1">
          <af:panelBox text="Region" id="pb1">
            <f:facet name="toolbar"/>
            <af:commandButton text="showPopupBehavior" id="cb1" >
              <af:showPopupBehavior popupId="p1"/>
            </af:commandButton>
            <af:commandButton text="AdfPage.PAGE.findComponent JavaScript" id="cb2" actionListener="#{TestBean.popupTestJavaScript}"/>
            <af:commandButton text="RichPopup.Show() Java" id="cb3" actionListener="#{TestBean.popupTestJava}"/>
          </af:panelBox>
        </af:panelGroupLayout>
      </af:group>
    </jsp:root>TestBean.java
    package view;
    import javax.faces.context.FacesContext;
    import javax.faces.event.ActionEvent;
    import oracle.adf.view.rich.component.rich.RichPopup;
    import org.apache.myfaces.trinidad.component.UIXGroup;
    import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
    import org.apache.myfaces.trinidad.util.Service;
    public class TestBean {
        private RichPopup testPopup;
        private UIXGroup popupGroup;
        public TestBean() {
        public void setTestPopup(RichPopup testPopup) {
            this.testPopup = testPopup;
        public RichPopup getTestPopup() {
            return testPopup;
        public void popupTestJava(ActionEvent actionEvent) {
            if(testPopup != null){
                RichPopup.PopupHints ph = new RichPopup.PopupHints();
                testPopup.show(ph);
            }else{
                System.err.println("TestBean.testPopop IS NULL!");
        public void popupTestJavaScript(ActionEvent actionEvent) {
            showPopupTest("r1:0:p1");
        private static void showPopupTest(String popupId) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            ExtendedRenderKitService service =
                Service.getRenderKitService(facesContext,
                                            ExtendedRenderKitService.class);
            service.addScript(facesContext,
                              "AdfPage.PAGE.findComponent('" + popupId + "').show();");
        public void setPopupGroup(UIXGroup popupGroup) {
            this.popupGroup = popupGroup;
        public UIXGroup getPopupGroup() {
            return popupGroup;
    }

    Thanks that fixed the problem.
    "a user error"
    Well I followed your book! Chapter 6 of the "Oracle Fusion Developer Guide - Working with Bounded Task Flows in ADF Regions". I think this comes back to book writer error. I found almost no mention of BackingBeanScope in this chapter. Don't you think this would be an important note?
    "did you know that there is a Java API (on the RichPopup instance) to launch a popup ?"
    Yes I posted in my code! If you read the above code you would see it there.
    I don't really understand why the scope of the bean has anything to do with af:showPopupBehavior or AdfPage.PAGE.findComponent.

  • 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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • 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 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);
    }

  • Make a JComboBox With JTextField Appear Empty?

    greetings all
    i have a JComboBox With a JTextField
    and the JComboBox Always Appear with the First value in the array or in the vector
    but i want it to appear empty when the program runs,how to do that?

    You only want to do that if you want to allow the user to select the null value in the course of running the program. If not, Joerg22's solution is the correct one.
    db

Maybe you are looking for

  • HT1229 i need to back- up my photos from my MacBook air to my iPad- how do i do this?

    HT1229 did not help me- does any one know how to back up the photos on my computer to my iPad?

  • Sales by Item in Sap Bo

    Hello Everyone I need to create a Query to get the Sales by Item, im using OINV, INV1, OITM, i have invoices canceled, so is necessary to use ORIN, RIN1 Im using a UDF as a factor to get pieces to kilograms, thats why i need sales in quantity or piec

  • Best practices for handling large messages in JCAPS 5.1.3?

    Hi all, We have ran into problems while processing larges messages in JCAPS 5.1.3. Or, they are not that large really. Only 10-20 MB. Our setup looks like this: We retrieve flat file messages with from an FTP server. They are put onto a JMS queue and

  • R/3 Table Name.

    Hi All, I have a list of say 600 field names along with their table names. (eg MARA table & BUKRS field) Now, i want to have the technical propertires of all those fields in the R/3 (only the data type and the length). So, is there any way out for de

  • Disable Bluetooth running at startup.

    How can i disable bluetooth running each time windows starts, as i want it _only sometimes_ - not always. My notebook is A200 23W and i have wi-fi always on.