Plz help me to put two columns in JCombobox

hi everyone...
Please help anyone to display two column in a jComboBox.......
I want the smple coding.....
with regards
Anand

Hallo.
Afaik, it's not possible using only classes provided in java.swing/java.awt packages.
One possible solution is to use custom renderer. By default JList and JComboBox are rendered using single JLabel. Our renderes should use several labels put on panel as rendereing component. For information see "Providing custom renderer" in "How to Use Combo Boxes" tutorial article, please. http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html#renderer
Sample (functional but not very nice) code is below. Sorry, I've tried to make it as short as possible.
import java.awt.*;
import javax.swing.*;
public class Main extends JDialog {       
    Main() {       
        JComboBox jPiceList = new JComboBox(new Object[] {
            new Object[] { "Lemon", 0.5 },
            new Object[] { "Tee", 3 },
            new Object[] { "Pinguin", 1 },
        jPiceList.setRenderer(new MyRenderer());       
        add(jPiceList);       
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        pack();
    public static void main(String... args)
    throws Exception {               
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new Main().setVisible(true);
* This class use panel with two labels to render
* list (combobox) cell
class MyRenderer implements ListCellRenderer {
    JComponent rendererComponent;
    JLabel labels[] = { new JLabel(), new JLabel() };
    public MyRenderer() {
        // We use panel with two labels as renderer component
        rendererComponent = new JPanel();
        rendererComponent.setLayout(new GridBagLayout());
        // Add labels
        GridBagConstraints c = new GridBagConstraints();
        c.fill = c.HORIZONTAL;
        c.weightx = 0.1;
        rendererComponent.add(labels[0],c);
        rendererComponent.add(labels[1]);
    public Component getListCellRendererComponent(
            JList list, Object value, int index,
            boolean isSelected, boolean cellHasFocus) {
        Object rowData[] = (Object[])value;
        // Prepare colors
        Color foreground = isSelected?
            list.getSelectionForeground(): list.getForeground();
        Color background = isSelected?
            list.getSelectionBackground(): list.getBackground();
        // Set panel colors
        rendererComponent.setForeground(foreground);
        rendererComponent.setBackground(background);
        // TODO Prepare and set panel border for hint
        // @see DefaultListCellRenderer#getListCellRendererComponent        
        // Now set label value and colors
        int col = 0;
        for(JLabel label : labels) {
            label.setBackground(background);
            label.setForeground(foreground);
            label.setText( String.valueOf(rowData[col++]) );
        return rendererComponent;
}

Similar Messages

  • Putting two columns in one

    Hey Guys,
    there is my next question on sql.
    It is possible to put two columns in one and when, how do I implement it? If there is an opportunity, may I asked to explain it on a example. =)
    best regards
    wderr

    You can use concatenation:
    SQL> create table a (a1 varchar2(10), a2 varchar2(10));
    Table created.
    SQL> insert into a values ('str1','str2');
    1 row created.
    SQL> select a1, a2, a1||a2
      2  from a;
    A1         A2         A1||A2
    str1       str2       str1str2
    1 row selected.Max
    [My Italian Oracle blog| http://oracleitalia.wordpress.com/2010/02/07/aggiornare-una-tabella-con-listruzione-merge/]

  • How to put multi columns in JComboBox?

    I only need a table with two columns in combo box. For example, id and title. The id can be auto complete search. The two columns only are displayed in pop up. Thank you for any suggestion!

    I searched the forum using "jcombobox multiple columns". The first posting I read had a link to a posting with 4 different solutions.
    Why is it so hard to search the forum before posting a question????

  • Help, my toddler put two dvds in  player on my mac book pro.

    I have tried everything you do to eject a jammed single disc but none of it works for two cds, any idea?

    Take it in for service before something gets permanently damaged.

  • Problem displaying two columns in JCombobox using EnumerationBinding

    I am using a JComboBox with an EnumerationBinding where I selected two attributes to be displayed in the combobox. But, it displays the first one only.
    I am using jDeveloper 9.0.3 version(latest version).
    The code is as follows.
    public void jbinit(){
    JComboBox cb = new JComboBox();
    cb.setModel(JUComboBoxBinding.createNavigationBinding(panelBinding, cb, "RecPositionView", null, "RecPositionViewIter", new String[]{"Code", "Descr"}, null, null));
    The combobox only displays the code but I want the combobox to display the code as well as the Descr. Does anyone know how to do it?
    Thanks in advance.
    Urmila

    The combobox only displays the code but I want the combobox to display the code as well as the Descr. Does anyone know how to do it?
    You're running into a known bug 2610954.

  • Help my iPod won't let me download apps... I'll put my password in then it takes me to the app but then is just goes away then I do it again an it won't load or it will just go away again plz help I want to get apps

    Help my iPod won't let me download apps... I'll put my password in then it takes me to the app but then is just goes away then I do it again an it won't load or it will just go away again plz help I want to get apps

    You said you updated yur 1G iPod to 4.2.1. A 1G can only go to 3.1.3 and thus you must have jailbroken it to get to 4.2.1 and that can cause problems.
    ArealDJ wrote:
    I have the same problem.. apps won't download and won't open. I have a 1st Gen ipod touch and recently upgraded my MacBook Pro (2012) and as soon as I upgraded the iPod Touch to 4.2.1, this happened. I restored to factory defaults and still cannot dl and open apps. Any way to diagnose this problem? Apple tech charges $29.99 for out of warranty products and if I am reluctant to pay with them telling me its simply a hardware problem.

  • Error when splitting a Table into two columns - Please help!

    Hi!
    I have created a table in which I have created a header which has been split into 3 parts conisting of 2 columns. These all work fine. However, when I try to split the row below the header row into 2 columns, it does so but, in a way, connects the line inbetween the two columns with the line inbetween the two columns above and will not allow me to move it left or right by manually changing specs or dragging the line. Please help! (I'm using CS5 by the way!) Thank you!

    I suggest you begin with a pre-built CSS Layout.  DW has several to help jump start your projects.  Go to File > New Blank Page > HTML.  Select a layout from the 3rd panel and hit CREATE.  See screenshot.
    Save this layout as test.html and begin building your prototype page saving and validating code often during your work sessions.
    Code Validation Tools
    CSS - http://jigsaw.w3.org/css-validator/
    HTML - http://validator.w3.org/
    Good luck with your project!
    Nancy O.

  • My ipod touch 2g is on black screen.when i connect it to my pc it is not recognizing it.then i opened i tunes and put the phone in dfu mode it says an ipod is detected but it cannot be restored error 1600.plz help me...

    my ipod touch 2g is on black screen.when i connect it to my pc it is not recognizing it.then i opened i tunes and put the phone in dfu mode it says an ipod is detected but it cannot be restored error 1600.plz help me...

    Error 1604
    This error is often related to USB timing. Try changing USB ports, using a different dock connector to USB cable, and other available USB troubleshooting steps (troubleshooting USB connections. If you are using a dock, bypass it and connect directly to the white Apple USB dock connector cable. If the issue persists on a known-good computer, the device may need service.
    If the issue is not resolved by USB isolation troubleshooting, and another computer is not available, try these steps to resolve the issue:
    Connect the device to iTunes, confirm that the device is in Recovery Mode. If it's not in Recovery Mode,put it into Recovery Mode.
    Restore and wait for the error.
    When prompted, click OK.
    Close and reopen iTunes while the device remains connected.
    The device should now be recognized in Recovery Mode again.
    Try to restore again.
    If the steps above do not resolve the issue, try restoring using a known-good USB cable, computer, and network connection.
    Error 1600, 1601, 1602
    Follow the steps listed above for Error 1604. This error may also be resolved by disabling, deactivating, or uninstalling third-party security, antivirus, and firewall software. See steps in this article for details on troubleshooting security software.

  • Help with two columns

    So I have two columns on my page and when I type the left column spills over into the right column. But this is not what I want to happen. I want the text that I type on the left to stay on the left and the text on the right to stay on the right. Please Help!

    Welcome to Apple Discussions
    I'd use a text box for one column or the other or text boxes for both. You can then link the left box on one page to the left box on the next page.
    Another option is to use a two-column table, but I think text boxes is easier.

  • I deleted my download folder by accident  i waz moving it and it just deleted it and showed this smoke. i found it in my trash so put it on my dock then clicked on it and it shows preview?! plz help how do i get it back!!!

    i deleted my download folder by accident  i waz moving it and it just deleted it and showed this smoke. i found it in my trash so put it on my dock then clicked on it and it shows preview?! plz help how do i get it back!!!

    You need to restore the folder using the (Put back) selection (CTRL click).

  • I´ve made four Columns with text and an Image over the middle of two columns. How do I put a text u

    I´ve made four Columns with text and an Image over the middle of two columns. How do I put a text under the Image that spans over the Columns?

    Did you mean that?
    or
    Did you mean that?
    Let me know.

  • I keep on getting asked to put account details i do but it declines the details but then when i want to download a free game i still have to put my bank details plz help me been like this for around 8 months : please help

    I keep on getting asked to put account details i do but it declines the details but then when i want to download a free game i still have to put my bank details plz help me been like this for around 8 months :< please help

    Hi.
    I'm not sure of it's still possible to choose 'None' under payment method. Besides, I'm sure you would like to be able to buy paid Apps as well.
    Try edit your payment information from a PC/Mac instead of your phone.
    Open iTunes > Choose 'iTunes Store' > Upper right corner, select your account or 'Sign in' > (When signed in) Click your account and go to 'Settings'.
    Make sure your credit card qualify for use in the Apple Store.
    Best regards.

  • How do i merge these two VI's--PLZ HELP

    HI,
         I am fairly new to Labview.I created two separate VI's.How can i merge them?In my Arc_Project vi i have a tank 3 where sample is collected.After 5 mins the loop will stop and the sample collected from tank 3 will be drained out to Interim Storage.
    In the second Vi-Spatial Logic.vi all the five tanks drain the sample to Interim Storage too.How do i add the volume drained from VI 1 and V1 2.
    Plz help.Thank you for your time..
    Attachments:
    Arc_Project_20070915_2_Final.vi ‏140 KB
    Spatial Logic_2_Final.vi ‏223 KB

    Ahh, you guys are all blessed with gigantic monitors! Look at that front panel!!!
    To answer your question, SubVIs is the way to go.
    While you're at it, you should clear up some misconceptions you seem to have about "local variables". A local variable just points to the same front panel object, so reading an indicator via a local variable and then immediately writing that value back to the same indicator is useless. Nothing will change! What you labeled "Main loop" servers no purpose. Keep the terminals of the indicators and delete the rest! Same with the chart loop!
    You do way too many duplicate operations. For example you multiply five different wires with 0.1, using 5 diagram constants of 0.1. One would be enough! If you would multiply the headwater-tailwater difference with 0.1, you would do all in one operation and could eliminate all these other 0.1 multiplications. same result!
    See here for details:
    http://forums.ni.com/ni/board/message?board.id=BreakPoint&message.id=4201#M4201
    LabVIEW Champion . Do more with less code and in less time .

  • I have problom to running maps.when i put any direction route a massage popup. Direction could not be found between these location. I am ussing ios 6. Any body plz help me

    I have problom to running maps.when i put any direction route a massage popup. Direction could not be found between these location. I am ussing ios 6. Any body plz help me

    Read here, as such is not supported everywhere:
    http://www.apple.com/ios/feature-availability/

  • My friends put cydia on my ipod and other stuff from it like something who slide your apps differently how can i remove the both, plz help ..???

    My friend put cydia on my ipod and other stuff from it like something who slide your apps differently. How can I remove the both, I really want, plz help ...?

    They hacked it and may have caused damage to your device. Jailbreaking also voids your warranty and support from Apple. To restore to a clean state, restore in Recovery Mode: http://support.apple.com/kb/HT1808

Maybe you are looking for

  • Can I use an apple blog on my wix site?

    Hi I am a Toronto Jewelry designer and would like to use apple blog on my site. How do I insert it? my site is www.candicekingstewart.com Thank You

  • My mac gone very very slow please help

    Today i was doing my photoshops editing and setdenlly my mac freze and i need to restart and when i restart my mac gone slower than befor

  • Connecting external audio interfaces?! Issues, help needed!

    Ok well basically i'v always used a pc to do music using cubase and a variety of hardware including a steinberg mi4 external audio interface connected via usb. Now on my pc which is actually less powerful than my new macbook (the 2.2ghz model) the in

  • How to make my CNiGraph to be SingleThre​ad Support?

    How to make my CNiGraph to be SingleThread Support? I generate the member varialbe of my CNiGraph using class wizard. In that case, I have CNiGraph m_graph; in a header file of a dialog. If I just make it, CNiGraph m_graph(CNiInterface:ingleThread);

  • SAPUI5 Development Environment Installation Issues

    Hi I am new to this development environment and am experiencing problems installing the Eclipse environment, the way I understand it once I have installed Eclipse I need to install UI5 Team and UI5 Tools  packages, I did manage to install the UI5 too