File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "please someone help" Watch "please someone help" New topic

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

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.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);
btnClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
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)
I agree. Here's the link:
subject: please someone help
It's not a secret anymore!