Search code examples
javalinuxswingjcomboboxjava-6

jcombobox is listing but unable to select the items in linux java1.6


I am having a problem with jcombobox in linux java 1.6. The exact problem is the combo is listing the items when i click the combobox (down arrow) but it minimizes if the selection goes off. i.e I am unable to select the items in the list. The same code is working in windows(java1.5, 1.6) and linux(java 1.5). The prob is only in linux java 1.6.

Please help me to get out of this. Thanks in advance.

Below is the code, 

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JComboBoxDemo extends JPanel {


    public JComboBoxDemo() {
        String[] comboTypes = { "Numbers", "Alphabets", "Symbols" };
        // Create the combo box, and set 2nd item as Default
        JComboBox comboTypesList = new JComboBox(comboTypes);
        comboTypesList.setSelectedIndex(2);
        comboTypesList.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                JComboBox jcmbType = (JComboBox) e.getSource();
                String cmbType = (String) jcmbType.getSelectedItem();
                System.out.println(cmbType);
            }
        });
        // Set up the picture

        // Layout the demo
        setLayout(new BorderLayout());
        add(comboTypesList, BorderLayout.NORTH);

        setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
    }
    public static void main(String s[]) {
        JFrame frame = new JFrame("JComboBox Usage Demo");
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        frame.setContentPane(new JComboBoxDemo());
        frame.pack();
        frame.setVisible(true);
    }
}

Solution

  • Thanks for all your help.

    Finally i had found the solution after so much effort (Even its a simple solution).

    The issue got fixed when i call frame.setUndecorated(true);

    In my application we have customized OS, which will not support decorated frame.

    So when i call this method it works fine.