Forums Register Login

!!!! URGENT !!!!! JComboBox popup problem

+Pie Number of slices to send: Send
I have added JComboBox to a panel(with FlowLayout). Then I set model of comboBox with custom model(getting data from db).
ComboBox is populated properly, but when I click the down arrow to show popup, nothing happens... popup doesn't show at all . If I use arrow keys to change selection in comboBox, it works fine.
I also tried by adding itmes with JComboBox.addItem() instead of using custom model, still it had same problem...
Any idea why ? Please reply soon
Thanks
+Pie Number of slices to send: Send
Could we see some code? JDK Version? Operating System?
[ February 24, 2003: Message edited by: Gregg Bolinger ]
+Pie Number of slices to send: Send
Here is the code

public class TestTab extends JPanel{
public TestTab() {
//{{INIT_CONTROLS
setLayout(new BorderLayout());
Insets ins = getInsets();
setSize(800, 550);
//}}
JPanel searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));

// today string
SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yy");
String todayStr = fmt.format(new Date());
// from date
searchPanel.add(new JLabel("From : "));
_fromDateField = new JTextField(new DocumentFilter(8), todayStr, 8);
_fromDateField.setBounds(40, 5, 40,20);
_fromDateField.setPreferredSize(new Dimension(10, 20));
searchPanel.add(_fromDateField);
// end date
searchPanel.add(new JLabel("To : "));
_toDateField = new JTextField(new DocumentFilter(8), todayStr, 8);
_toDateField.setPreferredSize(new Dimension(10, 20));
searchPanel.add(_toDateField);
// cusip
searchPanel.add(new JLabel("CUSIP : "));
_cusipField = new JTextField(new DocumentFilter(8), null, 8);
_cusipField.setPreferredSize(new Dimension(10, 20));
searchPanel.add(_cusipField);

searchPanel.add(new JLabel("PARTNER : "));
_partnerCB = new JComboBox();
searchPanel.add(_partnerCB);
// search button
_searchButton = new JButton("Search");
_searchButton.setBackground(new java.awt.Color(51, 51, 102));
_searchButton.setForeground(new java.awt.Color(204, 204, 153));
searchPanel.add(_searchButton);
Panel panel1 = new Panel(new BorderLayout());
panel1.add(searchPanel, BorderLayout.NORTH);
// cusip detail label
_cusipDetailLabel = new JLabel();
Panel cusipDetailPanel = new Panel(new BorderLayout());
cusipDetailPanel.add(_cusipDetailLabel, BorderLayout.NORTH);
panel1.add(cusipDetailPanel, BorderLayout.CENTER);
_tab1 = new TableTab1();
Panel resultPanel = new Panel(new BorderLayout());
resultPanel.add(_tab1, BorderLayout.NORTH);
Panel panel2 = new Panel(new BorderLayout());
panel2.add(_tab1, BorderLayout.CENTER);
Panel mainPanel = new Panel(new BorderLayout());
mainPanel.add(panel1, BorderLayout.NORTH);
mainPanel.add(panel2, BorderLayout.CENTER);
add(mainPanel, BorderLayout.CENTER);
_searchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
Object object = event.getSource();
if (object == _searchButton) {
searchButtonActionPerformed();
}
}
}
);

initialize();


}
private void initialize(){
try{
String sql = "Select '--All Partners--' partner_id, 'All' name FROM dual Union ";
sql += UserTab2.PARTNER_TABLE_SELECT;
VBComboBoxModel partnerModel = new VBComboBoxModel(sql);
_partnerCB.setModel(partnerModel);


_partnerCB.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me){
System.out.println("***** partnerCB Mouse Clicked ");
}
});



}catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(this,"Exception while getting partner list - "+e.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
}
}
}
+Pie Number of slices to send: Send
Hi Seema,
NEVER EVER MIX AWT AND SWING COMPONENTS. In ur code sometimes JPanel is used and sometimes Panel is used.
Second thing : NEVER EVER SET THE COMPONENT'S SIZE AND POSITION EXPLICITLY. The layout manager will best decide the position and the component itself will best calculate it's size. However u may set preferred, maximum or minimum size of the components. Most of the times this is not needed but sometimes it may be necessary.
If u make ur code better then we may be able to answer
+Pie Number of slices to send: Send
Thanks Ashish,
I did find out what the problem was. It was because of mixing AWT and SWING. I changed it to se all swing, and it worked fine.
Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1232 times.
Similar Threads
Issue with ComboBox and Windows L&F
JComboBox with horizontall scroll bar
JComboBox in JTable & seletion using keyboard
Color the JComboBox
How can I make a GUI like this?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:59:10.