File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes please someone help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "please someone help" Watch "please someone help" New topic
Author

please someone help

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
Thank u in advance for whomever will take the time to help me
My problem is as follows. I have a JComboBox with a number of choices; and also a JButton which allows the user to clear his choice just made. So for example, the user picked the 2nd item on
the list and he wishes to clear it he presses clear. The problem is this I wish to fire an actionEvent only when an item is picked
not when clear is pressed. Because the way I have written the code when clear is pressed the first item in the JComboBox is picked which is blank, and this fires an actionEvent which I dont want to happen. How do I stop it? I hope this is clear....
ravindran shanmugam
Greenhorn

Joined: Aug 30, 2001
Posts: 15
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.awt.*;
public class Mycombo extends JFrame
{
public Mycombo()
{
JButton btnClear = new JButton("Clear");
final JComboBox cmbSelect = new JComboBox();
cmbSelect.addItem("");
cmbSelect.addItem("sdfw");
cmbSelect.addItem("mnbj");
cmbSelect.addItem("qerre");
cmbSelect.setEditable(true) ;
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
contentPane.setPreferredSize(new Dimension(400, 150));
contentPane.add(cmbSelect, BorderLayout.CENTER);
contentPane.add(btnClear, BorderLayout.SOUTH);
setContentPane(contentPane);
btnClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
cmbSelect.setSelectedItem("");
System.out.println("Selected value is "+ (cmbSelect.getSelectedItem()).toString()+ "edsrtger");
}
});
}
public static void main(String[] args)
{
JFrame frame = new Mycombo();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.pack();
frame.setVisible(true);
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please someone help
 
Similar Threads
urgent please help
JComboBox Mystery!
Having problem.. pls help..! Ugently..
KeyEvent - Keypress
JComboBox focus