Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

!!!! URGENT !!!!! JComboBox popup problem  RSS feed

 
Seema Hanji
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could we see some code? JDK Version? Operating System?
[ February 24, 2003: Message edited by: Gregg Bolinger ]
 
Seema Hanji
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
}
}
 
Ashish Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Seema Hanji
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!